<template>
  <pageTabelLayout :loadings="fullPageLoading">
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form
            v-if="changesTab == 1"
            ref="formRef1"
            size="small"
            :model="pageData"
            :rules="pageDataRules"
            layout="inline"
          >
            <div style="display: flex">
              <a-form-item
                label="公司"
                field="corporateId"
                label-col-flex="85px"
                style="width: 280px"
              >
                <FactoryCascade
                  :configCascader="configCascader2"
                  @changeCascader="changeCascader2"
                />
              </a-form-item>
              <a-form-item label="生产单号" label-col-flex="85px" style="width: 250px">
                <a-input
                  allow-clear
                  class="bacClass"
                  v-model="pageData.weavingCode"
                  @press-enter="huiche"
                />
              </a-form-item>
              <a-form-item label="织布单号" label-col-flex="85px" style="width: 250px">
                <a-input
                  allow-clear
                  class="bacClass"
                  v-model="pageData.planOrderCode"
                  @press-enter="huiche"
                />
              </a-form-item>
              <a-form-item label="机台号" label-col-flex="85px" style="width: 250px">
                <a-input
                  allow-clear
                  class="bacClass"
                  v-model="pageData.machineCode"
                  @press-enter="huiche"
                />
              </a-form-item>
              <a-form-item label="打印状态" label-col-flex="85px" style="width: 250px">
                <a-select
                  popup-container="html"
                  class="bacClass"
                  v-model="pageData.printState"
                  allow-clear
                  allow-search
                  @press-enter="huiche"
                >
                  <a-option :value="0">未打印</a-option>
                  <a-option :value="1">已打印</a-option>
                </a-select>
              </a-form-item>
            </div>
            <div style="display: flex">
              <a-form-item label="是否插单" label-col-flex="85px" style="width: 280px">
                <a-select
                  popup-container="html"
                  class="bacClass"
                  v-model="pageData.insertState"
                  allow-clear
                  allow-search
                  @press-enter="huiche"
                >
                  <a-option :value="0">未插单</a-option>
                  <a-option :value="1">已插单</a-option>
                </a-select>
              </a-form-item>
              <a-form-item label="开始时间" label-col-flex="85px" style="width: 250px">
                <a-date-picker
                  popup-container="html"
                  class="bacClass"
                  v-model="pageData.beginDate"
                />
              </a-form-item>
              <a-form-item label="结束时间" label-col-flex="85px" style="width: 250px">
                <a-date-picker popup-container="html" class="bacClass" v-model="pageData.endDate" />
              </a-form-item>
              <a-form-item label="需求开单状态" label-col-flex="85px" style="width: 250px">
                <a-select
                  popup-container="html"
                  class="bacClass"
                  v-model="pageData.needState"
                  allow-clear
                  allow-search
                  @press-enter="huiche"
                >
                  <a-option :value="0">未开需求单</a-option>
                  <a-option :value="1">已开需求单</a-option>
                </a-select>
              </a-form-item>
              <a-form-item label="楼层" label-col-flex="85px" style="width: 250px">
                <a-select
                  popup-container="html"
                  class="bacClass"
                  :options="pageData.storyList"
                  v-model="pageData.story"
                  allow-clear
                  allow-search
                  @press-enter="huiche"
                  @focus="storyFocus"
                />
              </a-form-item>
            </div>
            <div style="display: flex">
              <a-form-item label="生产状态" label-col-flex="85px" style="width: 400px">
                <a-checkbox-group v-model="pageData.productionStates">
                  <a-checkbox :value="0">等待</a-checkbox>
                  <a-checkbox :value="1">生产中</a-checkbox>
                  <a-checkbox :value="2">完成</a-checkbox>
                  <a-checkbox :value="3">暂停</a-checkbox>
                </a-checkbox-group>
              </a-form-item>
            </div>
          </a-form>
          <a-form v-if="changesTab == 2" size="small" :model="pageData2" layout="inline">
            <a-form-item label="织布单号">
              <!-- <a-select popup-container="html"  class="bacClass" :style="{ width: '200px' }" @search="handleSearch"
                                  v-model="pageData.lingliaodanhao" :filter-option="false" allow-search allow-clear
                                  @focus="focusSel">
                                  <a-option v-for="item in pageData.lingliaodanhaos">{{ item.planOrderCode }}</a-option>
                              </a-select> -->
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData2.zhibudanhao"
                @press-enter="huiche"
              />
            </a-form-item>
            <a-form-item label="原料编号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData2.yuanliaobianhao"
                @press-enter="huiche"
              />
            </a-form-item>
            <a-form-item label="原料名称">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData2.yuanliaomingc"
                @press-enter="huiche"
              />
            </a-form-item>
            <a-form-item label="排产日期">
              <a-range-picker
                popup-container="html"
                :style="{ width: '250px' }"
                class="bacClass"
                @select="onSelect"
                @clear="onClear"
              />
            </a-form-item>
            <a-form-item label="状态" label-col-flex="65px">
              <a-select
                popup-container="html"
                :style="{ width: '228px' }"
                class="bacClass"
                v-model="pageData2.statesState"
              >
                <a-option :value="0">未处理</a-option>
                <a-option :value="1">已处理</a-option>
                <a-option :value="2">全部</a-option>
              </a-select>
            </a-form-item>
          </a-form>
          <a-form v-if="changesTab == 3" size="small" :model="pageData3" layout="inline">
            <a-form-item
              label="公司"
              field="corporateId"
              label-col-flex="60px"
              style="width: 300px"
            >
              <FactoryCascade :configCascader="configCascader3" @changeCascader="changeCascader3" />
            </a-form-item>
            <a-form-item label="织布单号">
              <!-- <a-select popup-container="html"  class="bacClass" :style="{ width: '200px' }" @search="handleSearch"
                                  v-model="pageData.lingliaodanhao" :filter-option="false" allow-search allow-clear
                                  @focus="focusSel">
                                  <a-option v-for="item in pageData.lingliaodanhaos">{{ item.planOrderCode }}</a-option>
                              </a-select> -->
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData3.zhibudanhao"
              />
            </a-form-item>
            <a-form-item label="原料编号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData3.yuanliaobianhao"
              />
            </a-form-item>
            <a-form-item label="原料名称">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData3.yuanliaomingc"
              />
            </a-form-item>
            <a-form-item label="日期">
              <a-range-picker
                popup-container="html"
                :style="{ width: '250px' }"
                class="bacClass"
                @select="onSelect2"
                @clear="onClear2"
                v-model="DateListSelect"
              />
            </a-form-item>
            <a-form-item label="状态" label-col-flex="65px">
              <a-select
                popup-container="html"
                :style="{ width: '228px' }"
                class="bacClass"
                v-model="pageData3.statesState"
              >
                <a-option :value="0">未处理</a-option>
                <a-option :value="1">已处理</a-option>
                <a-option :value="2">已作废</a-option>
                <a-option :value="3">全部</a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="楼层" label-col-flex="65px">
              <a-select
                popup-container="html"
                :style="{ width: '228px' }"
                class="bacClass"
                v-model="pageData3.areaName"
                allow-clear
              >
                <a-option :value="item" v-for="item in areaNameList" :key="item">{{
                  item
                }}</a-option>
              </a-select>
            </a-form-item>
          </a-form>
        </div>
      </div>
      <div style="float: right">
        <Toolbar
          v-if="changesTab == 1"
          :items="[
            `查询`,
            // '暂停',
            // '取消暂停',
            // '增加机台',
            // '转机台',
            '打印布飞(新)',
            `打印机台纸`,
            `开需求单`,
            '开增补单',
            '导出',
          ]"
          @picking="pickings"
          @add="addHandler"
          @import="importHandler"
          @del="deleteHandler"
          @select="selectHandler"
          @zjjt="zjjts"
          @zjt="zjts"
          @excel="downloadHandler"
          @kzbds="kzbds"
          @paper="paper"
          @dyBoufeix="dyBoufeixs"
          @zt="zts"
          @qxzt="qxzts"
          @export="exportss"
          :totalssss="totalssss"
        >
        </Toolbar>
        <!-- <Toolbar v-if="changesTab == 1" :items="[`查询`]" @select="selectHandler">
          </Toolbar> -->
        <Toolbar
          v-if="changesTab == 2"
          :items="[`查询`, '审核', '作废']"
          @select="selectHandler"
          @audit="audits"
          @cel="cels"
          :totalssss="totalssss"
        >
        </Toolbar>
        <!-- `单据汇总` -->
        <Toolbar
          v-if="changesTab == 3"
          :items="[`查询`, '导出', '作废']"
          @select="selectCx"
          @xqHuiz="chuangjianlinliaodans"
          @export="exports"
          :totalssss="totalssss"
          @cel="celss"
        >
        </Toolbar>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
    </template>
    <template #pageTabel>
      <a-tabs :lazy-load="true" :justify="true" @change="aTabsChanges">
        <a-tab-pane title="生产单管理" :key="1" :style="{ height: '100%', width: '100%' }">
          <a-spin
            :loading="pageData.AgGridLoading"
            tip="加载中"
            dot
            style="height: 99%; width: 100%; z-index: 999"
          >
            <AgGridVuesCopys
              :rowHeight="33"
              :headerHeight="33"
              :suppressCopyRowsToClipboard="true"
              :suppressDragLeaveHidesColumns="true"
              rowSelection="multiple"
              @grid-ready="gridReady"
              @columnResized="onColumnResized"
              @columnMoved="onColumnMoved"
              @columnVisible="onColumnVisible"
              @FilterChanged="FilterChangeds"
              @SelectionChanged="aggridFs.clickAllSelectors"
              style="height: 92%"
              :defaultColDef="defaultColDef"
              class="ag-theme-alpine"
              :rowData="table.dataList"
              :columnDefs="tableColumns"
              :localeText="localeText1"
              @lenghensssss="lenghensssss"
            ></AgGridVuesCopys>
            <paginationCopys
              :page-size-options="pagingList1"
              :total="total"
              show-total
              show-jumper
              show-page-size
              @change="PageSize"
              @page-size-change="change1"
              style="justify-content: center"
              :page-size="pagination.pageSize"
              :current="pagination.page"
            />
          </a-spin>
        </a-tab-pane>
        <a-tab-pane title="增补单审核" :key="2" :style="{ height: '100%', width: '100%' }">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady2"
            @columnResized="onColumnResized2"
            @columnMoved="onColumnMoved2"
            @columnVisible="onColumnVisible2"
            @SelectionChanged="aggridFs1.clickAllSelectors"
            @FilterChanged="aggridFs1.onFilterChanged"
            style="height: 92%"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="zbdDatas"
            :columnDefs="zbdshss"
            :localeText="localeText1"
            @lenghensssss="lenghensssss"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="total2"
            show-total
            show-jumper
            show-page-size
            @change="PageSize2"
            @page-size-change="change12"
            style="justify-content: center"
            :page-size="size2"
            :current="page2"
          />
        </a-tab-pane>
        <a-tab-pane title="单据明细" :key="3" :style="{ height: '100%', width: '100%' }">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady3"
            @columnResized="onColumnResized3"
            @columnMoved="onColumnMoved3"
            @columnVisible="onColumnVisible3"
            style="height: 92%"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tc3DataList"
            :columnDefs="tc3"
            :localeText="localeText1"
            @lenghensssss="lenghensssss"
            @FilterChanged="FilterChangeds"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="pagesss.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSizes"
            @page-size-change="change1s"
            style="justify-content: center"
            :page-size="pagesss.size"
            :current="pagesss.page"
          />
        </a-tab-pane>
      </a-tabs>

      <!-- <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">

      </a-spin> -->
    </template>

    <div v-show="false">
      <newschedulelist></newschedulelist>
    </div>

    <!-- <paginationCopys :total="total" show-total show-jumper show-page-size @change="PageSize" @page-size-change="change1"
            :page-size="pagination.pageSize" :current="pagination.page" style="justify-content: center" /> -->
    <a-drawer
      ok-text="关闭"
      :drawer-style="{ zIndex: 9999 }"
      @ok="bc"
      @cancel="bc"
      :width="'100%'"
      :height="'100%'"
      :visible="bfShowAdd"
      popup-container="html"
      placement="bottom"
      :hide-cancel="true"
    >
      <template #title> 模版</template>
      <iframe v-if="bfShowAdd" style="width: 100%; height: 100%" :src="srcUrl"></iframe>
    </a-drawer>

    <el-dialog v-model="addWeightDialog3" :width="500" title="完结" top="35vh">
      <a-space>
        <a-button type="primary" @click="pjwj">平均分完结</a-button>
        <a-button type="primary" @click="zjwj">直接完结</a-button>
      </a-space>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="() => (addWeightDialog3 = false)">关闭</el-button>
        </span>
      </template>
    </el-dialog>

    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      popup-container=".table-page-body"
      height="100%"
      :visible="pageData.showAdd"
      placement="bottom"
      unmountOnClose
      @cancel="sideNo1"
      @ok="sideOks"
      :closable="false"
      :mask-closable="false"
      :ok-loading="pageData.drawerLoading"
    >
      <template #title>{{ pageData3.sideTitle3 }}</template>
      <div>
        <div>
          <a-row>
            <!-- <a-form ref="formRef" :model="dataForms" size="mini" layout="vertical">
            <div>
              <a-space> -->
            <a-col :span="6">
              <a-form-item label="需求单号" field="code">
                <!-- 标记 -->
                <a-input v-model="dataForms.planNeedCode" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="开单日期">
                <a-input v-model="dataForms.planDate" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="需求人">
                <a-input v-model="dataForms.tabulationPerson" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="备注">
                <a-input class="bacClass" v-model="dataForms.remark" />
              </a-form-item>
            </a-col>

            <!-- <a-form-item label="织布单号">
                  <a-input v-model="dataForms.planOrderCode" disabled :style="{ width: '280px' }" />
                </a-form-item>
                <a-form-item label="生产单号">
                  <a-input v-model="dataForms.weavingCode" disabled :style="{ width: '280px' }" />
                </a-form-item> -->

            <!-- </a-space> -->
            <!-- <a-form-item label="客户名称">
                  <a-input v-model="dataForms.customName" disabled :style="{ width: '280px' }" />
                </a-form-item>
                <a-form-item label="坯布名称">
                  <a-input v-model="dataForms.greyName" disabled :style="{ width: '280px' }" />`
                </a-form-item>`
                <a-form-item label="坯布编号">
                  <a-input v-model="dataForms.greyCode" disabled :style="{ width: '280px' }" />
                </a-form-item> -->
            <!-- <a-space> </a-space>
            </div>
          </a-form> -->
          </a-row>

          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            rowSelection="multiple"
            tableName="setingSelects-kxqd"
            :suppressDragLeaveHidesColumns="true"
            @grid-ready="gridReadyAz1"
            style="height: 70vh; width: 100%"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableColumns1List"
            :columnDefs="tableColumns1"
            :localeText="localeText1"
            :suppressColumnVirtualisation="true"
            :suppressRowVirtualisation="true"
          ></AgGridVuesCopys>

          <!-- <a-table size="mini" :scrollbar="true" sticky-header stripe style="height: 38vh;" :columns="tableColumns1"
            :data="tableColumns1List" :pagination="false" :bordered="{ headerCell: true }"> -->
          <!-- <template #pickPieceWeight="{ record }">
                            <a-input class="bacClass" v-model="record['pickPieceWeight']"></a-input>
                        </template>
                        <template #pickPieceNum="{ record }">
                            <a-input-number class="bacClass" v-model="record.pickPieceNum"></a-input-number>
                        </template> -->
          <!-- <template #needWeight="{ record }">
              <a-input-number class="bacClass" @change="needWeightChange(record)" :min="0.01" :precision="2"
                v-model="record.needWeight"></a-input-number>
            </template>
            <template #urgentState="{ record }">
              <a-switch :checked-value="1" :unchecked-value="0" v-model="record.urgentState"
                @change="jjStateChanges(record)">
                <template #checked> 加急 </template>
                <template #unchecked> 正常 </template>
              </a-switch>
            </template>
            <template #urgentCount="{ record }">
              <a-input-number :disabled="record.urgentState != 1" class="bacClass" v-model="record.urgentCount" :min="0"
                :max="record.needPieceNum" :precision="0" />
            </template>
            <template #needPieceNum="{ record }">
              <a-input-number class="bacClass" @change="needWeightChanges(record)" v-model="record.needPieceNum" :min="0"
                :precision="0" />
            </template>
            <template #pieceWeight="{ record }">
              <a-input-number class="bacClass" @change="needWeightChanges(record)" v-model="record.pieceWeight" :min="0"
                :precision="0" />
            </template>
            <template #remark="{ record }"> -->
          <!-- <a-select popup-container="html"  multiple @click="zdClicks" class="bacClass" v-model="record.remark" allow-clear allow-create>
                <a-option v-for="item in zdList" :value="item.detailName">
                  {{ item.detailName }}
                  <a-input v-model="item.detailName"/>
                </a-option>
              </a-select> -->
          <!-- <a-input placeholder="双击选择" class="bacClass" id="aInputs" v-model="record.remark"
                @dblclick="dblclicks(record)" />
            </template>
          </a-table> -->
        </div>
      </div>
    </a-drawer>

    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      popup-container=".table-page-body"
      height="100%"
      :visible="pageData.showAdd2"
      placement="bottom"
      unmountOnClose
      @cancel="sideNo12"
      @ok="sideOks2"
      :closable="false"
      :ok-loading="pageData.drawerLoading"
      :mask-closable="false"
    >
      <template #title> {{ pageData3.sideTitle3 }}</template>
      <div>
        <div>
          <a-row>
            <a-col :span="6">
              <a-form-item label="增补单号" field="code">
                <!-- 标记 -->
                <a-input v-model="dataForms2.planSupplementCode" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="开单日期">
                <a-input v-model="dataForms2.planDate" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="增补人">
                <a-input v-model="dataForms2.tabulationPerson" disabled />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="备注">
                <a-input class="bacClass" v-model="dataForms2.remark" />
              </a-form-item>
            </a-col>
            <!-- <a-form ref="formRef" :model="dataForms2" size="mini" layout="vertical">
            <div>
              <a-space> -->

            <!-- <a-form-item label="织布单号">
                  <a-input v-model="dataForms.planOrderCode" disabled :style="{ width: '280px' }" />
                </a-form-item>
                <a-form-item label="生产单号">
                  <a-input v-model="dataForms.weavingCode" disabled :style="{ width: '280px' }" />
                </a-form-item> -->
          </a-row>
          <!-- </a-space> -->
          <!-- <a-form-item label="客户名称">
                  <a-input v-model="dataForms.customName" disabled :style="{ width: '280px' }" />
                </a-form-item>
                <a-form-item label="坯布名称">
                  <a-input v-model="dataForms.greyName" disabled :style="{ width: '280px' }" />
                </a-form-item>
                <a-form-item label="坯布编号">
                  <a-input v-model="dataForms.greyCode" disabled :style="{ width: '280px' }" />
                </a-form-item> -->
          <!-- <a-space> </a-space>
            </div>
          </a-form> -->

          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            rowSelection="multiple"
            :suppressDragLeaveHidesColumns="true"
            @grid-ready="gridReadyAz"
            style="height: 70vh; width: 100%"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableColumns1List2"
            :columnDefs="tableColumns2"
            :suppressColumnVirtualisation="true"
            :suppressRowVirtualisation="true"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>

          <!-- <a-table size="mini" :scrollbar="true" sticky-header stripe style="height: 38vh;" :columns="tableColumns2"
            :data="tableColumns1List2" :pagination="false" :bordered="{ headerCell: true }"> -->
          <!-- <template #pickPieceWeight="{ record }">
                            <a-input class="bacClass" v-model="record['pickPieceWeight']"></a-input>
                        </template>
                        <template #pickPieceNum="{ record }">
                            <a-input-number class="bacClass" v-model="record.pickPieceNum"></a-input-number>
                        </template> -->
          <!-- <template #supplementWeight="{ record }">
              <a-input-number class="bacClass" @change="needWeightChange2(record)" :min="0.01" :precision="2"
                v-model="record.supplementWeight"></a-input-number>
            </template>
            <template #remark="{ record }"> -->
          <!-- <a-input class="bacClass" v-model="record.remark"></a-input> -->
          <!-- <a-select popup-container="html"  multiple @click="zdClicks" class="bacClass" v-model="record.remark" allow-clear allow-create>
                <a-option v-for="item in zdList" :value="item.detailName">
                  {{ item.detailName }}
                </a-option>
              </a-select> -->
          <!-- <a-input placeholder="双击选择" class="bacClass" id="aInputs" v-model="record.remark"
                @dblclick="dblclicks(record)" />
            </template>
            <template #urgentState="{ record }">
              <a-switch :checked-value="1" :unchecked-value="0" v-model="record.urgentState">
                <template #checked> 加急 </template>
                <template #unchecked> 正常 </template>
              </a-switch>
            </template>
            <template #urgentCount="{ record }">
              <a-input-number :disabled="record.urgentState != 1" class="bacClass" v-model="record.urgentCount" :min="0"
                :precision="0" />
            </template>
            <template #supplementPieceNum="{ record }">
              <a-input-number class="bacClass" @change="needWeightChange2s(record)" v-model="record.supplementPieceNum"
                :min="0" :precision="0" />
            </template>

            <template #pieceWeight="{ record }">
              <a-input-number class="bacClass" @change="needWeightChange2s(record)" v-model="record.pieceWeight" :min="0"
                :precision="0" />
            </template>
          </a-table> -->
        </div>
      </div>
    </a-drawer>

    <!-- 弹窗提示 -->
    <a-modal
      v-model:visible="tipModalConfig.visible"
      width="350px"
      @ok="tipModalOk"
      @cancel="tipModalConfig.visible = false"
    >
      <template #title>
        <span style="font-size: 16px; font-weight: 600; color: #000000">提示</span>
      </template>
      <div>调机单状态为已派工，请确认未开始调机</div>
    </a-modal>
  </pageTabelLayout>
  <el-dialog
    v-model="addWeightDialog"
    :width="500"
    title="选择规则"
    v-loading="pageData.addWeightLoading"
    top="35vh"
  >
    <div>未完工数量：{{ uncompletedQuantity }}</div>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="averageFinish">平均分完结</el-button>
        <el-button type="primary" @click="directCompletion"> 直接完结 </el-button>
      </span></template
    >
    pageData3.sideTitle
  </el-dialog>

  <el-dialog v-model="addWeightDialog2" :width="500" title="修改增补单" top="35vh">
    <div
      >增补件数:
      <a-input-number
        size="small"
        class="bacClass"
        style="width: 200px"
        :min="0"
        v-model="zbjsNumber"
      ></a-input-number>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="() => (addWeightDialog2 = false)">关闭</el-button>
        <el-button type="primary" @click="zbdUpdata">保存</el-button>
      </span>
    </template>
  </el-dialog>

  <a-modal :width="500" v-model:visible="visible" :on-before-ok="handleOk" @cancel="handleCancel">
    <template #title> 需求单汇总</template>
    <a-form ref="formRef2" layout="inline" :model="searchData" size="mini">
      <CorporateSectorCascader
        ref="corPor"
        :configCascader="configCascader"
        @changeCascader="changeCascader"
      />
      <a-form-item
        label="发货仓库"
        :rules="[{ required: true, message: '仓库必填' }]"
        field="warehouseId"
      >
        <a-select
          popup-container="html"
          class="bacClass"
          :style="{ width: '15rem' }"
          v-model="searchData.warehouseId"
          allow-clear
        >
          <a-option v-for="item in fhWhList" :value="item.id">
            {{ item.warehouseName }}
          </a-option>
        </a-select>
      </a-form-item>
    </a-form>
  </a-modal>

  <a-drawer
    :drawer-style="{ zIndex: 9999 }"
    :mask-closable="false"
    :width="400"
    :visible="pageData3.showAdd1"
    unmountOnClose
    @ok="sideOk333"
    @cancel="pageData3.showAdd1 = false"
    cancel-text="关闭"
    ok-text="保存"
  >
    <template #title>
      {{ pageData3.sideTitle }}
    </template>
    <div>
      <a-form ref="formRef" layout="horizontal" :model="objectOP">
        <a-form-item label-col-flex="85px" label="重量">
          <a-input-number class="bacClass" v-model="objectOP.needWeight" disabled :precision="2" />
        </a-form-item>
        <a-form-item label-col-flex="85px" label="件数">
          <a-input-number class="bacClass" v-model="objectOP.needPieceNum" @change="changeJs" />
        </a-form-item>
        <a-form-item label-col-flex="85px" label="加急件数">
          <a-input-number
            class="bacClass"
            v-model="objectOP.urgentCount"
            :max="objectOP.needPieceNum"
            :precision="0"
            :min="0"
          />
        </a-form-item>
      </a-form>
    </div>
  </a-drawer>

  <el-dialog v-model="dblclicksShow" :width="400" title="领料需求" top="35vh">
    <a-form-item label="需求选项">
      <a-select
        popup-container="html"
        multiple
        class="bacClass"
        v-model="fruitSelects"
        @change="convertToString"
      >
        <a-option v-for="item in zdList" :value="item.detailName">
          {{ item.detailName }}
        </a-option>
      </a-select>
      <!-- <a-button status="success" @click="convertToString" :disabled="fruitSelects == ''">转换</a-button> -->
    </a-form-item>
    <a-form-item label="需求编辑" label-col-flex="58px">
      <a-textarea
        :max-length="400"
        allow-clear
        show-word-limit
        class="bacClass"
        v-model="fruitSelectsRemark"
      ></a-textarea>
    </a-form-item>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="fruitSelectDsty"> 确认 </el-button>
      </span>
    </template>
  </el-dialog>

  <!-- 新增机台弹窗 -->
  <el-dialog v-model="dblclicksShowA1" :width="1080" :height="800" title="新增机台详情" draggable>
    <template #title>
      <div>
        <center style="font-size: 20px"> 新增机台详情</center>
      </div>
      <div style="margin-top: 15px">
        <!-- <a-form> -->
        <a-form-item label="机台号" label-col-flex="60px">
          <a-input
            class="bacClass"
            v-model="objectOB.urgentJTH"
            @press-enter="huiche1"
            :style="{ width: '200px' }"
          />
        </a-form-item>
        <!-- </a-form> -->
      </div>
      <div style="float: right">
        <el-button type="primary" @click="saveJMCX"> 查询</el-button>
      </div>
    </template>
    <AgGridVuesCopys
      :rowHeight="33"
      :headerHeight="33"
      :suppressCopyRowsToClipboard="true"
      rowSelection="multiple"
      :suppressDragLeaveHidesColumns="true"
      @grid-ready="gridReadyA1"
      style="height: 60vh; width: 100%"
      :defaultColDef="defaultColDef"
      class="ag-theme-alpine"
      :rowData="tcA1DataList"
      :columnDefs="tcA2"
      :localeText="localeText1"
    ></AgGridVuesCopys>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="() => (dblclicksShowA1 = false)">关闭</el-button>
        <el-button type="primary" @click="saveXZjt"> 确认 </el-button>
      </span>
    </template>
  </el-dialog>

  <!-- 转机台弹窗 -->
  <el-dialog v-model="dblclicksShowA2" :width="1080" :height="800" title="转机台详情" draggable>
    <AgGridVuesCopys
      :rowHeight="33"
      :headerHeight="33"
      :suppressCopyRowsToClipboard="true"
      :suppressDragLeaveHidesColumns="true"
      @grid-ready="gridReadyA2"
      style="height: 60vh; width: 100%"
      :defaultColDef="defaultColDef"
      class="ag-theme-alpine"
      :rowData="tcA2DataList"
      :columnDefs="tcA2"
      :localeText="localeText1"
    ></AgGridVuesCopys>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="() => (dblclicksShowA2 = false)">关闭</el-button>
        <el-button type="primary" @click="saveZjt"> 确认 </el-button>
      </span>
    </template>
  </el-dialog>

  <!-- 取消暂停弹窗 -->
  <el-dialog v-model="dblclicksShowA3" :width="400" draggable>
    <center><b style="font-size: 22px; color: red">温馨提示！</b></center>
    <template #footer>
      <span class="dialog-footer" style="display: flex; justify-content: space-between">
        <el-button size="large" type="primary" @click="saveZjtOP" style=""> 转机台 </el-button>
        <el-button size="large" type="success" @click="saveZjtOB"> 确认 </el-button>
        <el-button size="large" type="info" @click="() => (dblclicksShowA3 = false)"
          >关闭</el-button
        >
      </span>
    </template>
  </el-dialog>

  <!-- 插单弹窗 -->
  <el-dialog v-model="dblclicksShowA4" :width="1080" :height="800" draggable>
    <template #title>
      <div>
        <center style="font-size: 20px"> 插单详情</center>
      </div>
      <div style="margin-top: 15px">
        <el-radio-group v-model="pageData.radioA">
          <el-radio :label="0">向前插单</el-radio>
          <el-radio :label="1">向后插单</el-radio>
        </el-radio-group>
      </div>
      <div>
        <!-- <div style="float:left">
          <a-form-item label="机台号" label-col-flex="60px">
            <a-input class="bacClass" v-model="objectOB.urgentJTH2" :style="{ width: '200px' }" />
          </a-form-item>
        </div> -->
        <div style="float: left; margin-left: 15px">
          <a-form-item label="织布单号" label-col-flex="70px">
            <a-input class="bacClass" v-model="objectOB.urgentZBDH" :style="{ width: '200px' }" />
          </a-form-item>
        </div>
      </div>
      <div style="float: right">
        <el-button type="primary" @click="saveJMCX2"> 查询</el-button>
      </div>
    </template>
    <AgGridVuesCopys
      :rowHeight="33"
      :headerHeight="33"
      :suppressCopyRowsToClipboard="true"
      :suppressDragLeaveHidesColumns="true"
      @grid-ready="gridReadyA4"
      style="height: 60vh; width: 100%"
      :defaultColDef="defaultColDef"
      class="ag-theme-alpine"
      :rowData="tcA4DataList"
      :columnDefs="tcA4"
      :localeText="localeText1"
    ></AgGridVuesCopys>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="() => (dblclicksShowA4 = false)">关闭</el-button>
        <el-button type="primary" @click="saveCD"> 确认 </el-button>
      </span>
    </template>
  </el-dialog>

  <a-modal v-model:visible="visible1" :hide-title="true" @cancel="visible1 = false" :footer="false">
    <a-space>
      <el-button type="primary" @click="tjdd">停机等待</el-button>
      <el-button type="primary" @click="ztzzxyd">暂停转做下单</el-button>
    </a-space>
  </a-modal>

  <a-modal
    v-model:visible="finishModalVisible"
    @beforeOk="handleFinishModalOk"
    @cancel="handleFinishModalCancel"
    width="300px"
  >
    <template #title> 系统提示 </template>
    <div>是否确认完结 </div>
  </a-modal>
</template>

<script lang="ts" setup>
import { post, get } from '@/api/http'
import { useTable, useRowKey, usePagination, useRowSelection } from '@/hooks/table'
import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
import { ref, reactive, onMounted } from 'vue'
import Toolbar from '@/components/Toolbar.vue'
import { Form, Message, Modal, Pagination } from '@arco-design/web-vue'
import { FormInstance } from '@arco-design/web-vue/es/form'
import emitter from '@/hooks/useEventBus'
import validate from '@/hooks/useValidate'
import { baseURL } from '../../../api/axios.config'
import axios from 'axios'
import { EXELTABLE } from '@/utils/exportEXCEL'
import usePermission from '@/store/modules/permission'
import { localeText } from '@/api/aggridZw'
import { pagingList } from '@/api/paging'
import dayjs from 'dayjs'
import { tableColumns1 as tableColumns3 } from '../useTableList'
import WHService from '@/service/wh'
import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
import { saveOrUpdateGridState as saveOrUpdateGridState02 } from '@/hooks/useGridState'
import { saveOrUpdateGridState as saveOrUpdateGridState03 } from '@/hooks/useGridState'
import useAgGridFilterSelector from '@/utils/aggridFilterAllSelect'
import newschedulelist from '../newschedulelist/newschedulelist.vue'
import FactoryCascade from '@/components/FactoryCascade/index.vue'
import switchRender from '@/components/aggridCellRenDerer/switchRender.vue'
import setTableTotalRow from '@/utils/setTableTotalRow.ts'
import { ElMessageBox } from 'element-plus'
const fullPageLoading = ref(false)
const aggridFs = useAgGridFilterSelector()
const aggridFs1 = useAgGridFilterSelector()
const finishModalVisible = ref<boolean>(false)
const isPass = ref<boolean>(false) //判断一下是否及格 （计划条数-验布条数）取绝对值  <= 可完结条数 及格
const unPassNum = ref<any>() //不可完结的数量
const uncdNum = ref<any>()
const handleFinishModalOk = async () => {
  console.log(isPass.value, '1')
  if (isPass.value) {
    try {
      const res = await post({
        url: 'planSingle/planMachineTask/pmtAverageFinish',
        data: wjListObj.value,
      })
      if (res.code == 200) {
        Message.success(res.message)
        finishModalVisible.value = false
        doRefresh()
        return true
      } else {
        Message.error(res.message)
      }
    } catch (e) {
      console.log(e)
    }
  } else {
    console.log(unPassNum.value, '2')
    console.log(uncdNum.value, '3')
    Message.error(
      `验布条数和计划条数相差${unPassNum.value},大于客户可完结条数${uncdNum.value},不可完结`
    )
    return false
  }
}
const handleFinishModalCancel = () => {
  finishModalVisible.value = false
}

interface Cloth {
  merceryCode: string
}

interface ClothInfo {
  id: any
  weaveOrderType: any
  remark: any
}

const changesTab = ref(1)
const aTabsChanges = (val: any) => {
  changesTab.value = val
  if (changesTab.value == 1) {
    doRefresh()
  } else if (changesTab.value == 3) {
    doRefreshs()
  } else if (changesTab.value == 2) {
    doRefresh2()
  }
}
// 手工完结弹窗
const addWeightDialog = ref(false)
//未完结数量
const uncompletedQuantity = ref('')
//未完结按钮数据
const manualList = ref({ noFinishWeight: '' })
//直接完结
const directCompletion = async () => {
  try {
    pageData.addWeightLoading = true
    let { code, message } = await post({
      url: 'planSingle/planMachineTask/dataFinish',
      data: [manualList.value],
    })
    if (code == 200) {
      doRefresh()
      Message.success('直接完结成功')
      addWeightDialog.value = false
      pageData.addWeightLoading = false
      return
    }
    Message.error(message)
  } finally {
    pageData.addWeightLoading = false
  }
}
//平均分完结
const averageFinish = async () => {
  manualList.value.noFinishWeight = uncompletedQuantity.value
  try {
    pageData.addWeightLoading = true
    let { code, message } = await post({
      url: 'planSingle/planMachineTask/dataAverageFinish',
      data: [manualList.value],
    })
    if (code == 200) {
      doRefresh()
      Message.success('平均分完结成功')
      addWeightDialog.value = false
      pageData.addWeightLoading = false
      return
    }
    Message.error(message)
  } finally {
    pageData.addWeightLoading = false
  }
}
//手工完结按钮
const manualFinish = async (val: any) => {
  manualList.value = val
  //   Modal.confirm({
  //     title: '系统提示',
  //     content: '是否手工完结?',
  //     async onOk() {
  try {
    pageData.pageLoading = true
    let { code, message, data } = await post({
      url: 'planSingle/planMachineTask/getDataFinishNum',
      data: {
        planOrderCode: val.planOrderCode,
        machineCode: val.machineCode,
        weavingCode: val.weavingCode,
      },
    })
    if (code == 200) {
      console.log(data)
      if (data > 0) {
        uncompletedQuantity.value = data
        addWeightDialog.value = true
      } else {
        Message.success('完结成功')
      }
      //   doRefresh()
      pageData.pageLoading = false
      return
    }
    Message.error(message)
  } finally {
    pageData.pageLoading = false
  }
  //     },
  //   })
}
const storyFocus = () => {
  lc(pageData.firm)
}
const pagingList1: any = ref(pagingList)
const total = ref(0)
const page = ref(1)
const size = ref(10)

function PageSize(val: any) {
  pagination.page = val
  doRefresh()
}

function change1(val: any) {
  pagination.pageSize = val
  doRefresh()
}

const form: any = reactive({
  printState: '', //打印状态 0未打印 1已打印
  weavingCode: '', //"生产单号",
  planOrderCode: '', //"织布单号",
  machineCode: '', //"机台号",
  area: '', //"位置",
  productionStates: [0, 1, 3], //[0, 1, 2] 生产状态 0 等待 1 生产中  2 完成
  insertState: '',
  beginDate: '',
  endDate: '',
  needState: '',
})
const configCascader2 = ref<{}>({
  corporateWidth: '200px', //公司宽度
  size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
  cascaderShow: 'sector', //配置部门不显示
})
const changeCascader2 = (data: any) => {
  const { corporateId, sectorId, sectorLabel, corporateLabel } = data
  pageData.corporateId = corporateId
  pageData.corporateLabel = corporateLabel
  // if (pageData.corporateId && pageData.corporateLabel) {
  //   formRef1.value.resetFields()
  // }
}

const configCascader3 = ref<{}>({
  corporateWidth: '200px', //公司宽度
  size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
  cascaderShow: 'sector', //配置部门不显示
})
const changeCascader3 = (data: any) => {
  const { corporateId, sectorId, sectorLabel, corporateLabel } = data
  pageData3.corporateId = corporateId
  pageData3.corporateLabel = corporateLabel
  pageData3.areaName = ''
  getAreaNameList()
}
const headerShow = ref<boolean>(true)
//查询
const scrollbar = ref(true)
const dataLists = ref([])
function doRefresh() {
  formRef1.value?.validate().then((err: any) => {
    if (!err) {
      pageData.AgGridLoading = true
      updateGridState01()
      post({
        url: 'planSingle/planMachineTask/getPageInfo',
        data: {
          page: pagination.page,
          size: pagination.pageSize,
          firmId: pageData.corporateId,
          weavingCode: pageData.weavingCode,
          planOrderCode: pageData.planOrderCode,
          machineCode: pageData.machineCode,
          printState: pageData.printState,
          insertState: pageData.insertState,
          needState: pageData.needState,
          beginDate: pageData.beginDate,
          endDate: pageData.endDate,
          area: pageData.story,
          productionStates: pageData.productionStates,
        },
      })
        .then(({ data, code }: any) => {
          if (code === 200) {
            gridOption.value.setFilterModel(null)
            aggridFs.resetAgFs()
            table.handleSuccess(data.list)
            data.list.forEach(item=>{
              item.productedWeight=Number((item.actualWeight+item.hasProductWeight).toFixed(2))
            })
            gridOption.value.setRowData(data.list)
            console.log(data.list);
            
            total.value = data.total
            
            gridOption.value.setPinnedBottomRowData([
              {
                ckbox: '总计',
                badWeight: one(
                  data.list.map((res) => (res.badWeight ? Number(res.badWeight) : 0))
                ).toFixed(2),
                csNum: one(data.list.map((res) => (res.csNum ? Number(res.csNum) : 0))).toFixed(2),
                sgcNum: one(data.list.map((res) => (res.sgcNum ? Number(res.sgcNum) : 0))).toFixed(
                  2
                ),
                alreadyWeight: one(
                  data.list.map((res) => (res.alreadyWeight ? Number(res.alreadyWeight) : 0))
                ).toFixed(2),
                actualWeight: one(
                  data.list.map((res) => (res.actualWeight ? Number(res.actualWeight) : 0))
                ).toFixed(2),
                posteriorWeight: one(
                  data.list.map((res) => (res.posteriorWeight ? Number(res.posteriorWeight) : 0))
                ).toFixed(2),
                hasProductWeight: one(
                  data.list.map((res) => (res.hasProductWeight ? Number(res.hasProductWeight) : 0))
                ).toFixed(2),
                productedWeight: one(
                  data.list.map((res) => (res.productedWeight ? Number(res.productedWeight) : 0))
                ).toFixed(2),
              },
            ])
            console.log(gridOption.value);

          }
        })
        .catch(console.log)
        .finally(() => {
          pageData.AgGridLoading = false
        })
    }
  })
}

function one(arr) {
  let sum = 0
  for (var i = 0; i < arr.length; i++) {
    sum += arr[i]
  }
  return sum
}

const { selectedRowKeys, onSelectionChange } = useRowSelection()
const pagination = usePagination(doRefresh)
const table = useTable()
const rowKey = useRowKey('id')
//检验表单是否含有中文的方法
const hasChiese = validate.includeChinese
//当前点击暂停按钮行id 用于弹窗确认事件
const currentStopId = ref(null)
const currentInsertId = ref(null)
const tableColumns = [
  {
    field: '',
    headerCheckboxSelection: true,
    checkboxSelection: true,
    width: 50,
    showDisabledCheckboxes: false,
    pinned: 'left',
  },
  {
    headerName: '公司',
    field: 'outSouringCompany',
    width: 150,
  },
  {
    headerName: '生产序号',
    field: 'serialNum',
    width: 150,
  },
  {
    headerName: '生产单号',
    field: 'weavingCode',
    width: 150,
  },
  {
    headerName: '织布单号',
    field: 'planOrderCode',
    width: 150,
    cellRenderer: {
      template: `
        <div v-if="params.data.ckbox=='总计'"></div><span style="color:#165dff;" @click="a1">{{ params.data.planOrderCode }}</span>`,
      setup(props: any) {
        const a1 = () => {
          post({
            url: 'planSingle/planOrder/getPageInfo',
            data: {
              planOrderCode: props.params.data.planOrderCode,
              page: 1,
              size: 10,
            },
          }).then(({ data, code, message }) => {
            if (code == 200) {
              emitter.emit('setingSaxq', data.list[0])
            } else {
              Message.error(message)
            }
          })
        }
        return {
          a1,
        }
      },
    },
  },
  {
    headerName: '开单时间',
    field: 'planDate',
    width: 150,
  },
  {
    headerName: '次布重量',
    field: 'badWeight',
    width: 150,
  },
  {
    headerName: '落布匹数',
    field: 'csNum',
    width: 150,
  },
  {
    headerName: '验布匹数',
    field: 'sgcNum',
    width: 150,
  },
  {
    headerName: '客户',
    field: 'customName',
    width: 150,
  },
  {
    headerName: '机台号',
    field: 'machineCode',
    width: 200,
  },
  {
    headerName: '楼层',
    field: 'area',
    width: 450,
  },
  {
    headerName: '指令重量',
    field: 'orderWeight',
    width: 150,
  },
  {
    headerName: '分配重量',
    field: 'alreadyWeight',
    width: 150,
  },
  {
    headerName: '未检验重量',
    field: 'actualWeight',
    width: 150,
  },
  {
    headerName: '验后重量',
    field: 'posteriorWeight',
    width: 150,
  },
  {
    headerName: '未生产重量',
    field: 'productWeight',
    width: 150,
    valueGetter: (params: any) => {
      //分配重量-（未检验重量+磅布重量）
      return (
        Number(params.data.alreadyWeight) -
        (Number(params.data.actualWeight) + Number(params.data.hasProductWeight))
      ).toFixed(2)
    },
  },
  {
    headerName: '磅布重量',
    field: 'hasProductWeight',
    width: 150,
  },
  {
    headerName: '已生产重量',
    field: 'productedWeight',
    width: 150,
    valueGetter: (params: any) => {
      return (Number(params.data.actualWeight)+Number(params.data.hasProductWeight)).toFixed(2)
    },
  },
  {
    headerName: '坯布编号',
    field: 'greyCode',
    width: 150,
  },
  {
    headerName: '坯布名称',
    field: 'greyName',
    width: 150,
  },
  {
    headerName: '坯布批号',
    field: 'greyBatchNo',
    width: 150,
  },
  {
    headerName: '织造交期',
    field: 'weavDeliveryDate',
    width: 150,
  },
  {
    headerName: '预计上线时间',
    field: 'pStartTime',
    width: 150,
  },
  {
    headerName: '实际上线时间',
    field: 'actualStartTime',
    width: 150,
  },
  {
    headerName: '预计完成时间',
    field: 'pEndTime',
    width: 150,
  },
  {
    headerName: '实际完成时间',
    field: 'actualEndTime',
    width: 150,
  },
  {
    headerName: '完结时间',
    field: 'actualEndTime',
    width: 150,
  },
  {
    headerName: '织布单类型',
    field: 'businessType',
    width: 150,
  },
  {
    headerName: '针寸数',
    field: 'workDrum',
    width: 150,
  },
  {
    headerName: '颜色',
    field: 'colorName',
    width: 150,
  },
  {
    headerName: '纱长',
    field: 'yarnLength',
    width: 150,
  },
  {
    headerName: '纱批',
    field: 'batch',
    width: 150,
  },
  {
    headerName: '织布单备注',
    field: 'poRemark',
    width: 150,
  },
  {
    headerName: '调机情况',
    field: 'adjustmentState',
    width: 150,
  },
  {
    headerName: '领料情况',
    key: 'materialState',
    dataIndex: 'materialState',
    width: 150,
  },
  {
    headerName: '插单标识时间',
    key: 'insertTime',
    dataIndex: 'insertTime',
    width: 150,
  },
  {
    headerName: '插单时间',
    key: 'actualInsertTime',
    dataIndex: 'actualInsertTime',
    width: 150,
  },
  {
    headerName: '暂停时间',
    key: 'suspendTime',
    dataIndex: 'suspendTime',
    width: 150,
  },
  {
    headerName: '暂停标识',
    field: 'stopType',
    width: 100,
  },

  {
    headerName: '需求开单状态',
    field: 'needState',
    width: 100,
    cellRenderer: {
      template: `
        <div v-if="params.data.ckbox=='总计'"></div><span>{{ a1 }}</span>`,
      setup(props: any) {
        return {
          a1: props.params.data.needState == 0 ? '未开需求单' : '已开需求单',
        }
      },
    },
    filterParams: {
      valueFormatter: function (params: any) {
        return params.value == '0' ? '未开需求单' : '已开需求单'
      },
    },
  },
  {
    headerName: '生产状态',
    field: 'productionState',
    width: 80,
    cellRenderer: {
      template: `
        <div v-if="params.data.ckbox=='总计'"></div><span>{{ a1 }}</span>`,
      setup(props: any) {
        return {
          a1:
            props.params.data.productionState == 0
              ? '等待'
              : props.params.data.productionState == 1
              ? '生产中'
              : props.params.data.productionState == 2
              ? '完成'
              : '暂停',
        }
      },
    },
    filterParams: {
      valueFormatter: function (params: any) {
        return params.value == '0'
          ? '等待'
          : params.value == '1'
          ? '生产中'
          : params.value == '2'
          ? '完成'
          : '暂停'
      },
    },
  },
  {
    headerName: '插单标识',
    field: 'insertState',
    width: 80,
    cellRenderer: {
      template: `
        <div v-if="params.data.ckbox=='总计'"></div>
        <a-checkbox v-model="states" disabled></a-checkbox>`,
      setup(props: any) {
        return {
          states: props.params.data.insertState == 0 ? false : true,
        }
      },
    },
  },
  {
    headerName: '打印状态',
    field: 'printState',
    width: 80,
    cellRenderer: {
      template: `
        <div v-if="params.data.ckbox=='总计'"></div><span>{{ a1 }}</span>
        `,
      setup(props: any) {
        return {
          a1: props.params.data.printState == 0 ? '未打印' : '已打印',
        }
      },
    },
    filterParams: {
      valueFormatter: function (params: any) {
        return params.value == '0' ? '未打印' : '已打印'
      },
    },
  },
  {
    headerName: '操作',
    field: 'action',
    width: 260,
    pinned: 'right',
    cellRenderer: {
      template: `
        <a-space>
          <el-button style="color:#165dff;" v-if="params.data.stopType"  link @click="onStop">暂停</el-button>
          <el-button style="color:#165dff;" v-if="params.data.productionState==3" link @click="cancelStop">取消暂停</el-button>
          <el-button style="color:#165dff;" v-if="params.data.productionState != 2" link @click="a1">完结</el-button>
          <el-button style="color:#ccc;" link v-if="params.data.productionState == 2" disabled>完结</el-button>
          <el-button style="color:#165dff;" v-if="params.data.serialNum == 2&&params.data.insertState==1" link @click="insertOrder">插单</el-button>

        </a-space>
        `,
      setup(props: any) {
        const a1 = () => {
          wjListObj.value = props.params.data
          ElMessageBox.confirm(
            `<div style="color: red;">织布单号${props.params.data.planOrderCode}是否已完成车间转料或车间退料</div>`,
            '系统提示',
            {
              dangerouslyUseHTMLString: true, // 使用HTML片段
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
              // onOk() {
              //   fullPageLoading.value = true
              //   getFinishInfo(props.params.data)
              // },
            }
          ).then(() => {
            fullPageLoading.value = true
            getFinishInfo(props.params.data)
          })
          // addWeightDialog3.value = true
        }
        const a2 = () => {
          editHandler1(props.params.data)
        }
        const a3 = () => {
          editHandler3(props.params.data)
        }
        const onStop = async () => {
          //生产状态为等待 并且调机情况为已派工的 弹窗提示
          if (
            props.params.data.productionState == 0 &&
            props.params.data.adjustmentState == '已派工'
          ) {
            currentStopId.value = props.params.data.id
            tipModalConfig.contorlType = '暂停'
            tipModalConfig.visible = true
          } else {
            try {
              const res = await post({
                url: 'planSingle/planMachineTask/setSuspend',
                data: {
                  id: props.params.data.id,
                },
              })
              if (res.code == 200) {
                doRefresh()
                Message.success(res.message)
              } else {
                Message.error(res.message)
              }
            } catch (e) {
              console.log(e)
            }
          }
        }
        const cancelStop = async () => {
          try {
            const res = await post({
              url: 'planSingle/planMachineTask/setSuspend',
              data: {
                id: props.params.data.id,
                noStopType: 1,
              },
            })
            if (res.code == 200) {
              doRefresh()
              Message.success(res.message)
            } else {
              Message.error(res.message)
            }
          } catch (e) {
            console.log(e)
          }
        }

        const insertOrder = async () => {
          try {
            const res = await post({
              url: 'planSingle/planMachineTask/insertPmt',
              data: {
                id: props.params.data.id,
              },
            })
            if (res.code == 200) {
              doRefresh()
              Message.success(res.message)
            } else {
              currentInsertId.value = props.params.data.id
              tipModalConfig.contorlType = '插单'
              tipModalConfig.visible = true
            }
          } catch (e) {
            console.log(e)
          }
        }
        return {
          a1,
          a2,
          a3,
          onStop,
          cancelStop,
          insertOrder,
        }
      },
    },
    cellStyle: (params: any) => {
      if (params.node.rowPinned == 'bottom') return { display: 'none' }
    },
  },
]

//弹窗
const tipModalConfig = reactive({
  contorlType: '',
  visible: false,
})

const tipModalOk = async () => {
  try {
    if (tipModalConfig.contorlType == '暂停') {
      const res = await post({
        url: 'planSingle/planMachineTask/setSuspend',
        data: {
          id: currentStopId.value,
        },
      })
      if (res.code == 200) {
        tipModalConfig.visible = false
        Message.success(res.message)
        doRefresh()
      } else {
        Message.error(res.message)
      }
    } else if (tipModalConfig.contorlType == '插单') {
      const res = await post({
        url: 'planSingle/planMachineTask/insertPmt',
        data: {
          id: currentInsertId.value,
          isInsert: 1,
        },
      })
      if (res.code == 200) {
        tipModalConfig.visible = false
        Message.success(res.message)
        doRefresh()
      } else {
        Message.error(res.message)
      }
    }
  } catch (e) {
    console.log(e)
  }
}
const scroll = {
  x: 2000,
  y: 200,
}
const tablediv = ref(null)
const pageData: any = reactive({
  clothList: [],
  showAdd: false,
  showAdd2: false,
  sideTitle: '新增布料基础资料',
  dropDownData: '',
  dropDownData2: '',
  pageLoading: false,
  theight: 0,
  tablediv: null,
  rHeight: 0,
  btnList: [],
  isEdit: false,
  dropDownData3: 0,
  addWeightLoading: false,
  radioA: 0,
  corporateId: '', //公司id
  corporateLabel: '', //公司名
  weavingCode: '', //生产单号
  planOrderCode: '', //织布单号
  machineCode: '', //机台号
  printState: '', //打印状态
  productionStates: [0, 1, 3], //[0, 1, 2] 生产状态 0 等待 1 生产中  2 完成
  insertState: '', //是否插单
  beginDate: '', //开始时间
  endDate: '', //结束时间
  needState: '', //需求开单状态
  story: '', //楼层
  storyList: [], //楼层数组
  AgGridLoading: false,
  drawerLoading: false,
})
const formRef1 = ref<FormInstance>()
const pageDataRules = reactive<any>({
  corporateId: [{ required: true, message: '请选择公司', trigger: 'change' }],
})
//下拉框得到焦点
const focusSel = () => {
  selCxAll({ yarnCode: '', deleteState: 0 })
}
//下拉数据
const options = ref<any>(pageData.clothList)
const loading = ref(false)
const handleSearch = (value: any) => {
  if (value) {
    const ob = { yarnCode: value, deleteState: 0 }
    loading.value = true
    selCxAll(ob)
    options.value = pageData.clothList
    loading.value = false
  } else {
    options.value = []
  }
}

//下拉框查询
function selCxAll(val: any) {
  post({
    url: 'product/Yarn/getFieldValue',
    data: val,
  }).then(({ data, code }: any) => {
    if (code === 200) {
      pageData.clothList = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}
function lc() {
  try {
    post({
      url: '/planSingle/planSchedul/getMachineAreaPara',
      data: {
        firm: pageData.corporateLabel,
      },
    }).then((res: any) => {
      if (res.code == 200) {
        pageData.storyList = res.data.map((item: any) => {
          return {
            label: item,
            value: item,
          }
        })
      }
    })
  } catch (e) {
    console.log(e)
  }
}
onMounted(() => {
  updateGridState01()
  updateGridState02()
  updateGridState03()
  pageData.rHeight = document.getElementsByClassName('main-section')[0]?.clientHeight
  //弹出层的高
  if (pageData.rHeight !== undefined) {
    pageData.rHeight = pageData.rHeight
  }
  // 切换tap到本页面执行的方法
  emitter.on('setingSelects', () => {
    // selCxAll({});
    doRefresh()
  })
  doRefresh()
})

//查询
const selectHandler = () => {
  pagination.page = 1
  page2.value = 1
  if (changesTab.value == 1) {
    doRefresh()
  } else {
    doRefresh2()
  }
}
const queryData = reactive({
  clothType: '',
})
const addHandler = () => {
  for (var key in dataForm) {
    if (key === 'id') {
      dataForm[key] = null
    } else {
      dataForm[key] = ''
    }
  }
  pageData.showAdd = true
  pageData.sideTitle = '新增织单类型'
}

const dataForm = reactive<ClothInfo>({
  id: null,
  weaveOrderType: '',
  remark: '',
})
const gridOption = ref()
const colState = ref()
const gridReady = (params: any) => {
  gridOption.value = params.api
  colState.value = params.columnApi
  //gridOption.value.sizeColumnsToFit();
}
const gridOptionA4 = ref()
const gridReadyA4 = (params: any) => {
  gridOptionA4.value = params.api
}

const gridOptionA2 = ref()
const gridReadyA2 = (params: any) => {
  gridOptionA2.value = params.api
}

const gridOptionA1 = ref()
const gridReadyA1 = (params: any) => {
  gridOptionA1.value = params.api
}
const gridOptionAz = ref()
const gridReadyAz = (params: any) => {
  gridOptionAz.value = params.api
}
const gridOptionAz1 = ref()
const gridReadyAz1 = (params: any) => {
  gridOptionAz1.value = params.api
}

const formRef = ref<FormInstance>()
const sideOk = () => {
  formRef.value?.validate().then((err) => {
    if (!err) {
      pageData.pageLoading = true
      if (pageData.sideTitle === '新增织单类型') {
        dataForm.id = null
        post({
          url: 'planSingle/weaveOrderType/insert',
          data: [dataForm],
        })
          .then((res: any) => {
            if (res.code === 200) {
              formRef.value?.resetFields()

              pageData.showAdd = false

              Message.success({
                content: '新增成功',
                duration: 5000,
              })
              doRefresh()
            } else {
              Message.error({
                content: res.message,
                duration: 5000,
              })
            }
          })
          .finally(() => {
            pageData.pageLoading = false
          })
      } else {
        post({
          url: 'planSingle/weaveOrderType/update',
          data: [dataForm],
        })
          .then((res: any) => {
            if (res.code === 200) {
              formRef.value?.resetFields()
              pageData.showAdd = false
              Message.success({
                content: '修改成功',
                duration: 5000,
              })
              doRefresh()
            } else {
              Message.error({
                content: res.message,
                duration: 5000,
              })
            }
          })
          .finally(() => {
            pageData.pageLoading = false
          })
      }
    }
  })
}
const deleteHandler = () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return
  }
  Modal.confirm({
    title: '系统提示',
    content: '确认删除选中的数据?',
    onOk() {
      pageData.pageLoading = true
      post({
        url: 'planSingle/weaveOrderType/deleteZT',
        data: gridOption.value.getSelectedRows().map((o: any) => {
          return o.id
        }),
      })
        .then(({ code, message }: any) => {
          if (code === 200) {
            Message.success({
              content: '删除成功',
              duration: 5000,
            })

            pagination.page = 1
            doRefresh()
          } else {
            Message.error({
              content: message,
              duration: 5000,
            })
          }
        })
        .finally(() => {
          pageData.pageLoading = false
        })
    },
  })
}
const editHandler = (record: ClothInfo) => {
  dataForm.id = record.id
  dataForm.weaveOrderType = record.weaveOrderType
  dataForm.remark = record.remark
  pageData.sideTitle = '修改织单类型'
  pageData.showAdd = true
}
//判断是否填写了中文
const isChiese = (value: string, cb: Function) => {
  return new Promise<void>((resolve) => {
    if (window.encodeURI(value).indexOf('%') !== -1) {
      cb('填写的值只能是英文数字组合或英文，数字！')
    }
    resolve()
  })
}
//input离开焦点 将小写转大写
// const inputBlur = () => {
//     dataForm.yarnCode = dataForm.yarnCode.toUpperCase();
// }
//导出
const exportss = () => {
  post({
    url: '/planSingle/planMachineTask/getExportExcel',
    data: {
      ...form,
    },
  }).then(({ data, code }: any) => {
    if (code === 200) {
      EXELTABLE(tableColumns, data, '生产单管理')
    }
  })
}
const exports = () => {
  post({
    url: '/planSingle/planNeed/getPageInfoAll',
    data: {
      deleteState: 0,
      auditState: 0,
      startDate: DateListSelect.value[0],
      endDate: DateListSelect.value[1],
      planOrderCode: pageData2.zhibudanhao,
      rawmaterialCode: pageData2.yuanliaobianhao,
      rawmaterialName: pageData2.yuanliaomingc,
      // disposeState: pageData2.statesState == 2 ? undefined : pageData2.statesState
    },
  }).then((res: any) => {
    if (res.code === 200) {
      const ob = res.data.map((item: any) => {
        const { cnState, ...rest } = item
        return rest
      })
      console.log(ob)
      EXELTABLE(tc3, ob, '生产单管理-单据明细')
    } else {
      Message.error({
        content: res.message,
        duration: 5000,
      })
    }
  })
}

function tableToXlsx(head: any, filename: any, body: any) {
  const uri = 'data:application/vnd.ms-excel;base64,',
    template = `<html>
            <head><meta charset="UTF-8"></head>
            <body><table border="1"><tr>${head}</tr>${body}</table></body>
        </html>`

  const a = document.createElement('a')
  a.href = uri + window.btoa(unescape(encodeURIComponent(template)))
  a.download = filename
  a.click()
  document.removeChild(a)
}

//模板下载
const downloadHandler = () => {
  // axios.get(baseURL + '/product/Yarn/uploadModel', {
  //     responseType: 'blob',
  //     headers: {
  //         token: sessionStorage.getItem('USER-TOKEN-KEY')
  //     }
  // }).then((res) => {
  //     if (res.status === 200) {
  //         filedownload(res.data, '纱线类别.xlsx')
  //     }
  // })
}
//导入
const importHandler = () => {
  const inputEle: HTMLInputElement = document.createElement('input')
  inputEle.type = 'file'
  inputEle.id = 'fileUploadExcel'
  inputEle.accept =
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'
  inputEle.addEventListener('change', (e) => {
    const formData = new FormData()
    if (inputEle.files !== null) {
      formData.append('file', inputEle.files[0] || '')
    } else {
      Message.warning('未选择文件！')
      return
    }
    pageData.pageLoading = true
    axios
      .post(baseURL + '/product/Yarn/analyseYarnWireModel', formData, {
        headers: {
          'Content-Type': 'multipart/form-data',
          token: sessionStorage.getItem('USER-TOKEN-KEY'),
        },
      })
      .then((result) => {
        if (result.data['code'] === 200) {
          Message.success('导入成功')
        } else {
          Message.error(result.data.message)
        }
      })
      .finally(() => {
        pageData.pageLoading = false
        doRefresh()
      })
  })
  inputEle.click()
}
//设置权限
// ['查询', '新增', '删除', '导出', '导入']
const permissionStore = usePermission()

if (permissionStore.hasPermisson('blzl.cx')) {
  pageData.btnList.push('查询')
}
if (permissionStore.hasPermisson('blzl.xz')) {
  pageData.btnList.push('新增')
}
if (permissionStore.hasPermisson('blzl.sc')) {
  pageData.btnList.push('删除')
}
if (permissionStore.hasPermisson('blzl.dc')) {
  pageData.btnList.push('导出')
}
if (permissionStore.hasPermisson('blzl.dr')) {
  pageData.btnList.push('导入')
}
if (permissionStore.hasPermisson('blzl.xg')) {
  pageData.isEdit = true
}
const handleChange = (_data: any) => {
  table.handleSuccess(_data)
}
const getFinishState2 = async (obj: any) => {
  try {
    const { id } = obj
    const res = await post({
      url: 'planSingle/planMachineTask/getFinishMessage',
      data: {
        id,
        messageState: '66',
      },
    })
    if (res.code == 200) {
      const result = await post({
        url: 'planSingle/planMachineTask/pmtAverageFinish',
        data: wjListObj.value,
      })
      try {
        if (result.code == 200) {
          Message.success(result.message)
          doRefresh()
        } else {
          Message.error(result.message)
        }
      } catch (e) {
        console.log(e)
      }
    } else {
      Modal.confirm({
        title: '系统提示',
        content: res.message,
        async onOk() {
          fullPageLoading.value = true
          const result = await post({
            url: 'planSingle/planMachineTask/pmtAverageFinish',
            data: wjListObj.value,
          })
          try {
            if (result.code == 200) {
              Message.success(result.message)
              doRefresh()
            } else {
              Message.error(result.message)
            }
          } catch (e) {
            console.log(e)
          } finally {
            fullPageLoading.value = false
          }
        },
      })
    }
  } catch (e) {
    console.log(e)
  } finally {
    fullPageLoading.value = false
  }
}
const wjListObj: any = ref()
//点击完结按钮 弹窗确认 调用的第一个接口
const getFinishState = async (obj: any) => {
  try {
    const { id } = obj
    const res = await post({
      url: 'planSingle/planMachineTask/getFinishMessage',
      data: {
        id,
        messageState: '6',
      },
    })
    if (res.code == 200) {
      getFinishState2(obj)
    } else {
      fullPageLoading.value = false
      Modal.confirm({
        title: '系统提示',
        content: res.message,
        onOk() {
          fullPageLoading.value = true
          getFinishState2(obj)
        },
      })
    }
  } catch (e) {
    console.log(e)
  } finally {
    fullPageLoading.value = false
  }
}
//点击主表每一行的完结按钮 调接口获取信息（状态、可完结条数、验布条数、计划条数）
const getFinishInfo = async (data: any) => {
  const res = await post({
    url: 'planSingle/planMachineTask/getFinishState',
    data: data,
  })
  try {
    if (res.code == 200) {
      if (res.data.finishState == 0) {
        const { cdNum, poNum, sgcNum } = res.data
        uncdNum.value = cdNum
        isPass.value = cdNum >= Math.abs(poNum - sgcNum)
        if (!isPass.value) unPassNum.value = Math.abs(poNum - sgcNum)
        //0的时候要弹确认弹窗
        finishModalVisible.value = true
      } else if (res.data.finishState == 1) {
        getFinishState(data)
        //1的时候直接掉平均分完结接口
      }
    } else {
      Message.error(res.message)
    }
  } catch (e) {
    console.log(e)
  }
  fullPageLoading.value = false
}
let a = [
  {
    showRowGroup: 'hide_def',
    headerName: '',
    field: 'ckbox',
    checkboxSelection: true,
    headerCheckboxSelection: true,
    pinned: 'left',
    width: 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: 'left',
  },
]
const defaultColDef: any = {
  sortable: true,
  resizable: true,
  filter: true,
}
const localeText1: any = ref(localeText)
const huiche = () => {
  doRefresh()
}
const huiche1 = () => {
  saveJMCX()
}
const rangeValue: any = ref([dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')])

const khmctList: any = ref([])
const khmctLists: any = ref([])
const khmctList1: any = ref([])

const khmctSelect = () => {
  post({
    url: 'planSingle/planMachineTask/getDropValue',
    data: {
      value: '',
      name: 'machineCode',
    },
  }).then((res: any) => {
    if (res.code == 200) {
      khmctList.value = res.data
    }
  })
}
const khmctSelects = () => {
  post({
    url: 'planSingle/planMachineTask/getDropValue',
    data: {
      value: '',
      name: 'area',
    },
  }).then((res: any) => {
    if (res.code == 200) {
      khmctLists.value = res.data
    }
  })
}
const khmctSelect1 = () => {
  post({
    url: 'planSingle/planMachineTask/getDropValue',
    data: {
      value: '',
      name: 'planOrderCode',
    },
  }).then((res: any) => {
    if (res.code == 200) {
      khmctList1.value = res.data
    }
  })
}
const changes = (e: any) => {
  if (e == undefined || e == '') {
    rangeValue.value = ['', '']
  }
}

//开需求单按钮
const pickings = async () => {
  if (gridOption.value.getSelectedRows().length == 0) {
    Message.error('请勾选')
    return
  }
  pageData.AgGridLoading = true
  //自动生成接口
  const res: any = await post({
    url: 'planSingle/planNeed/getAutomaticInfo',
  })
  if (res.code == 200) {
    dataForms.planNeedCode = res.data.planNeedCode
    dataForms.planDate = res.data.planDate
    dataForms.tabulationPerson = res.data.tabulationPerson
    const resq: any = await post({
      url: '/planSingle/planNeed/getNeedDetail',
      data: gridOption.value.getSelectedRows(),
    })
    if (resq.code == 200) {
      tableColumns1List.value = resq.data
      pageData3.sideTitle3 = '开需求单'
      pageData.showAdd = true
    } else {
      Message.error(resq.message)
    }
  } else {
    Message.error(res.message)
  }
  pageData.AgGridLoading = false
}

const sideNo1 = () => {
  for (let item in dataForms) {
    dataForms[item] = ''
  }
  tableColumns1List.value = []
  pageData.showAdd = false
  pageData.drawerLoading = false
  pageData.AgGridLoading = false
}

const sideOks = async () => {
  const planNeedList = tableColumns1List.value.map((item: any) => {
    item.brandName = item.yarnCard
    item.yarnBatch = item.batch
    return item
  })
  pageData.drawerLoading = true
  const res: any = await post({
    url: 'planSingle/planNeed/insert',
    data: {
      ...dataForms,
      planNeedList,
    },
  })
  if (res.code == 200) {
    for (let item in dataForms) {
      dataForms[item] = ''
    }
    tableColumns1List.value = []
    pageData.showAdd = false
    doRefresh()
    Message.success(res.message)
  } else {
    Message.error(res.message)
  }
  pageData.drawerLoading = false
}

import inputRender from '@/components/aggridCellRenDerer/inputRender.vue'

let dataForms: any = reactive({})
const tableColumns1: any[] = [
  {
    showRowGroup: 'hide_def',
    headerName: '',
    checkboxSelection: true,
    headerCheckboxSelection: true,
    pinned: 'left',
    width: 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: 'left',
  },
  {
    headerName: '织布单号',
    field: 'planOrderCode',
  },
  {
    headerName: '生产单号',
    field: 'weavingCode',
  },
  {
    headerName: '客户名称',
    field: 'customName',
  },
  {
    headerName: '坯布编号',
    field: 'greyCode',
  },
  {
    headerName: '坯布名称',
    field: 'greyName',
  },
  // {
  //     headerName: "排产日期",
  //     field: "schedulDate",
  //     dataIndex: "schedulDate",
  //     width: 150,
  // },
  {
    headerName: '机台号',
    field: 'machineCode',
  },
  {
    headerName: '原料编号',
    field: 'rawmaterialCode',
  },
  {
    headerName: '原料名称',
    field: 'rawmaterialName',
  },
  {
    headerName: '纱牌',
    field: 'yarnCard',
  },
  {
    headerName: '纱批',
    field: 'batch',
  },
  {
    headerName: '色号',
    field: 'colorCode',
  },
  {
    headerName: '色称',
    field: 'colorName',
  },
  {
    headerName: '等级',
    field: 'level',
  },
  {
    headerName: '织布单应领总数',
    field: 'planWantNeedNum',
  },
  {
    headerName: '织布单已领总数',
    field: 'planBeforeNeedNum',
  },
  {
    headerName: '织布单未领总数',
    field: 'planNotNeedNum',
  },
  {
    headerName: '生产单应领总数',
    field: 'weavWantNeedNum',
  },
  {
    headerName: '生产单已领总数',
    field: 'weavBeforeNeedNum',
  },
  {
    headerName: '生产单未领总数',
    field: 'weavNotNeedNum',
  },
  {
    headerName: '计划需求重量',
    field: 'planNeedWeight',
  },
  {
    headerName: '整件个数',
    field: 'pieceCount',
  },
  {
    headerName: '需求重量',
    field: 'needWeight',
    cellRenderer: inputRender,
    valueSetter: (params: any) => {
      const newValue = params.newValue

      if (isNaN(newValue)) {
        params.data.needWeight = 0
        return true
      }
        params.data.needWeight = newValue
        params.data.needPieceNum = Math.ceil(params.data.needWeight / params.data.pieceWeight)
        params.data.needWeight=Number((params.data.needPieceNum*params.data.pieceWeight).toFixed(2))
      return true
    },
  },
  {
    headerName: '需求件数',
    field: 'needPieceNum',
    cellRenderer: inputRender,
    valueSetter: (params: any) => {
      const newValue = params.newValue
      params.data.needPieceNum = newValue
        params.data.needWeight = parseFloat(
          (Number(params.data.needPieceNum) * Number(params.data.pieceWeight)).toFixed(2)
        )
      return true
    },
  },
  {
    headerName: '整件件重',
    field: 'pieceWeight',
    cellRenderer: inputRender,
    valueSetter: (params: any) => {
      const newValue = params.newValue
      params.data.pieceWeight = newValue
        params.data.needWeight = parseFloat(
          (Number(params.data.needPieceNum) * Number(params.data.pieceWeight)).toFixed(2)
        )
      return true
    },
  },
  {
    headerName: '机台余纱量',
    field: 'surplusWeight',
  },
  {
    headerName: '领料需求',
    field: 'remark',
    cellRenderer: {
      template: `
      <div style="height:100%;width: 100%;" @dblclick="a">{{val.remark}}&nbsp;</div>`,
      setup(props: any) {
        const val = ref(props.params.data)
        const a = () => {
          dblclicks(props.params.data)
        }
        return {
          val,
          a,
        }
      },
    },
  },
  {
    headerName: '是否加急',
    field: 'urgentState',
    cellRenderer: switchRender,
    cellRendererParams: {
      key: 'urgentState',
      switchChange: (params: any, newValue: any) => {
        try {
          if (newValue == 1) {
            params.data['urgentCount'] = params.data.needPieceNum
            console.log(params.data.urgentCount)
            if (!params.data.remark) {
              params.data.remark = `加急（${params.data.urgentCount}）`
            } else {
              params.data.remark += `加急（${params.data.urgentCount}）`
            }
          } else {
            if (!params.data.remark) {
              if (!params.data.urgentCount) {
                params.data.urgentCount = 0
              }
            } else {
              params.data.remark = params.data.remark.replace(/加急（\d+）/g, '')
              params.data.urgentCount = 0
            }
          }
          params.setValue(params.data.urgentState)
          // console.log(gridOptionAz1.value,'value')
        } catch (error) {
          // console.log(error)
        }
      },
    },
  },
  {
    headerName: '加急件数',
    field: 'urgentCount',
    cellRenderer: {
      template: `<a-input-number class="bacClass" @change="c" v-model="val.urgentCount" :disabled="val.urgentState != 1" :max="val.needPieceNum" :min="0" />`,
      setup(props: any) {
        const val = ref(props.params.data)
        const c = () => {
          needCount3(props.params.data)
        }
        return {
          c,
          val,
        }
      },
    },
  },
]
const needCount3 = (data: any) => {
  if (data.urgentState == 1) {
    if (!data.remark) {
      data.remark = `加急（${data.urgentCount}）`
    } else {
      data.remark = data.remark.replace(/加急（\d+）/g, `加急（${data.urgentCount}）`)
    }
  }
  tableColumns1List.value = [...tableColumns1List.value]
}

const needCount2 = (data: any) => {
  if (data.needPieceNum != 0 && data.pieceWeight != 0) {
    data.needWeight = parseFloat((Number(data.needPieceNum) * Number(data.pieceWeight)).toFixed(2))
  } else {
    data.needPieceNum = 0
    data.needWeight = 0
  }
  tableColumns1List.value = [...tableColumns1List.value]
}

const needCount1 = (data: any) => {
  if (data.needWeight != 0 && data.pieceWeight != 0) {
    data.needPieceNum = Math.ceil(data.needWeight / data.pieceWeight)
  } else {
    data.needPieceNum = 0
    data.needWeight = 0
  }
  tableColumns1List.value = [...tableColumns1List.value]
}

const tableColumns1List: any = ref([])
const needWeightChange = (e: any) => {
  if (e['needWeight'] != 0 && e['pieceWeight'] != 0) {
    e['needPieceNum'] = Math.ceil(e['needWeight'] / e['pieceWeight'])
  } else {
    nextTick(() => {
      e['needPieceNum'] = 0
      e['needWeight'] = 0
    })
  }
}
const needWeightChanges = (e: any) => {
  if (e['needPieceNum'] != 0 && e['pieceWeight'] != 0) {
    // debugger
    e['needWeight'] = e['needPieceNum'] * e['pieceWeight']
  } else {
    nextTick(() => {
      e['needPieceNum'] = 0
      e['needWeight'] = 0
    })
  }
}
const needWeightChange2 = (e: any) => {
  if (e['supplementWeight'] != 0 && e['pieceWeight'] != 0) {
    e['supplementPieceNum'] = Math.ceil(e['supplementWeight'] / e['pieceWeight'])
  } else {
    nextTick(() => {
      e['supplementWeight'] = 0
      e['supplementPieceNum'] = 0
    })
  }
}
const needWeightChange2s = (e: any) => {
  if (e['supplementPieceNum'] != 0 && e['pieceWeight'] != 0) {
    e['supplementWeight'] = e['supplementPieceNum'] * e['pieceWeight']
  } else {
    nextTick(() => {
      e['supplementWeight'] = 0
      e['supplementPieceNum'] = 0
    })
  }
}
let dataForms2: any = reactive({})
const tableColumns2: any[] = [
  {
    showRowGroup: 'hide_def',
    headerName: '',
    checkboxSelection: true,
    headerCheckboxSelection: true,
    pinned: 'left',
    width: 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: 'left',
  },
  {
    headerName: '织布单号',
    field: 'planOrderCode',
  },
  {
    headerName: '生产单号',
    field: 'weavingCode',
  },
  {
    headerName: '客户名称',
    field: 'customName',
  },
  {
    headerName: '坯布编号',
    field: 'greyCode',
  },
  {
    headerName: '坯布名称',
    field: 'greyName',
  },
  // {
  //     headerName: "排产日期",
  //     field: "schedulDate",
  //     dataIndex: "schedulDate",
  //     width: 150,
  // },
  {
    headerName: '机台号',
    field: 'machineCode',
  },
  {
    headerName: '原料编号',
    field: 'rawmaterialCode',
  },
  {
    headerName: '原料名称',
    field: 'rawmaterialName',
  },
  {
    headerName: '纱牌',
    field: 'yarnCard',
  },
  {
    headerName: '纱批',
    field: 'batch',
  },
  {
    headerName: '色号',
    field: 'colorCode',
  },
  {
    headerName: '色称',
    field: 'colorName',
  },
  {
    headerName: '等级',
    field: 'level',
  },
  {
    headerName: '织布单应领总数',
    field: 'planWantNeedNum',
  },
  {
    headerName: '织布单已领总数',
    field: 'planBeforeNeedNum',
  },
  {
    headerName: '生产单应领总数',
    field: 'weavWantNeedNum',
  },
  {
    headerName: '生产单已领总数',
    field: 'weavBeforeNeedNum',
  },
  {
    headerName: '计划需求重量',
    field: 'planNeedWeight',
  },
  {
    headerName: '整件个数',
    field: 'pieceCount',
  },
  {
    headerName: '增补重量',
    field: 'supplementWeight',
    cellRenderer: inputRender,
    valueSetter: (params: any) => {
      const newValue = params.newValue
      params.data.supplementWeight = newValue

      if (isNaN(newValue)) {
        params.data.supplementWeight = 0
        return true
      }
        params.data.supplementPieceNum = Math.ceil(params.data.supplementWeight / params.data.pieceWeight)
        params.data.supplementWeight=Number((params.data.supplementPieceNum*params.data.pieceWeight).toFixed(2))
      return true
    },
  },
  {
    headerName: '增补件数',
    field: 'supplementPieceNum',
    cellRenderer: inputRender,
    valueSetter: (params: any) => {
      const newValue = params.newValue
      params.data.supplementPieceNum = newValue
        params.data.supplementWeight = Number((params.data.supplementPieceNum * params.data.pieceWeight).toFixed(2))
      return true
    },
  },
  {
    headerName: '整件件重',
    field: 'pieceWeight',
    cellRenderer: inputRender,
    valueSetter: (params: any) => {
      const newValue = params.newValue
      params.data.pieceWeight = newValue
      params.data.supplementWeight = Number((params.data.supplementPieceNum * params.data.pieceWeight).toFixed(2))
      return true
    },
  },
  {
    headerName: '机台余纱量',
    field: 'surplusWeight',
  },
  {
    headerName: '领料需求',
    field: 'remark',
    cellRenderer: {
      template: `
        <div style="height:100%;width: 100%;" @dblclick="a">
          {{val.remark}}&nbsp;
          </div>`,
      setup(props: any) {
        const val = ref(props.params.data)
        const a = () => {
          dblclicks(props.params.data)
        }
        return {
          val,
          a,
        }
      },
    },
  },
  {
    headerName: '是否加急',
    field: 'urgentState',
    cellRenderer: switchRender,
    cellRendererParams: {
      key: 'urgentState',
      switchChange: (params: any, newValue: any) => {
        try {
          if (newValue == 1) {
            params.data['urgentCount'] = params.data.supplementPieceNum
            if (!params.data.remark) {
              params.data.remark = `加急（${params.data.urgentCount}）`
            } else {
              params.data.remark += `加急（${params.data.urgentCount}）`
            }
          } else {
            if (!params.data.remark) {
              if (!params.data.urgentCount) {
                params.data.urgentCount = 0
              }
            } else {
              params.data.remark = params.data.remark.replace(/加急（\d+）/g, '')
              params.data.urgentCount = 0
            }
          }
          params.setValue(params.data.urgentState)
        } catch (error) {
          console.log(error)
        }
      },
    },
  },
  {
    headerName: '加急件数',
    field: 'urgentCount',
    cellRenderer: {
      template: `<a-input-number class="bacClass" v-model="val.urgentCount" :disabled="val.urgentState != 1" @change="c" :max="val.supplementPieceNum" :min="0" />`,
      setup(props: any) {
        const val = ref(props.params.data)
        const c = () => {
          supplementCount3(props.params.data)
        }

        return {
          c,
          val,
        }
      },
    },
  },
]

const supplementCount1 = (data: any) => {
  if (data.supplementWeight != 0 && data.pieceWeight != 0) {
    data.supplementPieceNum = Math.ceil(data.needWeight / data.pieceWeight)
  } else {
    data.supplementPieceNum = 0
    data.supplementWeight = 0
  }
  tableColumns1List2.value = [...tableColumns1List2.value]
}

const supplementCount2 = (data: any) => {
  if (data.supplementPieceNum != 0 && data.pieceWeight != 0) {
    data.supplementWeight = data.supplementPieceNum * data.pieceWeight
  } else {
    data.supplementPieceNum = 0
    data.supplementWeight = 0
  }
  tableColumns1List2.value = [...tableColumns1List2.value]
}
const supplementCount3 = (data: any) => {
  if (data.urgentState == 1) {
    if (!data.remark) {
      data.remark = `加急（${data.urgentCount}）`
    } else {
      data.remark = data.remark.replace(/加急（\d+）/g, `加急（${data.urgentCount}）`)
    }
  }
  tableColumns1List2.value = [...tableColumns1List2.value]
}

const tableColumns1List2: any = ref([])
const kzbds = async () => {
  if (gridOption.value.getSelectedRows().length == 0) {
    Message.error('请勾选')
    return
  }

  // if (gridOption.value.getSelectedRows().length > 1) {picking是
  //   Message.error('只能勾选一条')
  //   return
  // }
  //自动生成接口
  const res: any = await post({
    url: 'planSingle/planSupplement/getAutomaticInfo',
  })
  if (res.code == 200) {
    dataForms2.planSupplementCode = res.data.planSupplementCode
    dataForms2.planDate = res.data.planDate
    dataForms2.tabulationPerson = res.data.tabulationPerson
    const resq: any = await post({
      url: '/planSingle/planNeed/getNeedDetail',
      data: gridOption.value.getSelectedRows(),
    })
    if (resq.code == 200) {
      tableColumns1List2.value = resq.data
      pageData3.sideTitle3 = '开增补单'
      pageData.showAdd2 = true
    } else {
      Message.error(resq.message)
    }
  } else {
    Message.error(res.message)
  }
}
const sideNo12 = () => {
  for (let item in dataForms2) {
    dataForms2[item] = ''
  }
  tableColumns1List2.value = []
  pageData.showAdd2 = false
}
const sideOks2 = async () => {
  for (let i = 0; i < tableColumns1List2.value.length; i++) {
    if (
      tableColumns1List2.value[i].supplementWeight == 0 ||
      tableColumns1List2.value[i].supplementWeight == undefined ||
      tableColumns1List2.value[i].supplementWeight == null
    ) {
      Message.error('增补重量不可为0')
      return
      break
    }
  }
  pageData.drawerLoading = true
  const res: any = await post({
    url: 'planSingle/planSupplement/insert',
    data: {
      ...dataForms2,
      planSupplementList: tableColumns1List2.value.map((res: any) => {
        // res['remark'] = res.remark.toString()
        res.brandName = res.yarnCard
        res.yarnBatch = res.batch
        return res
      }),
    },
  })
  if (res.code == 200) {
    for (let item in dataForms2) {
      dataForms2[item] = ''
    }
    tableColumns1List2.value = []
    pageData.showAdd2 = false
    Message.success(res.message)
  } else {
    Message.error(res.message)
  }
  pageData.drawerLoading = false
}
const zbdList = [
  {
    title: '公司',
    key: 'companyName',
    dataIndex: 'companyName',
    width: 150,
  },
  {
    title: '增补单号',
    key: 'planSupplementCode',
    dataIndex: 'planSupplementCode',
    width: 150,
  },
  {
    title: '织布单号',
    key: 'planOrderCode',
    dataIndex: 'planOrderCode',
    width: 150,
  },
  {
    title: '客户名称',
    key: 'customName',
    dataIndex: 'customName',
    width: 150,
  },
  {
    title: '原料编号',
    key: 'rawmaterialCode',
    dataIndex: 'rawmaterialCode',
    width: 150,
  },
  {
    title: '原料名称',
    key: 'rawmaterialName',
    dataIndex: 'rawmaterialName',
    width: 200,
  },
  {
    title: '机台号',
    key: 'machineCode',
    dataIndex: 'machineCode',
    width: 150,
  },
  {
    title: '排产日期',
    key: 'schedulDate',
    dataIndex: 'schedulDate',
    width: 150,
  },
  {
    title: '增补重量',
    key: 'supplementWeight',
    dataIndex: 'supplementWeight',
    slotName: 'supplementWeight',
    width: 150,
  },
  {
    title: '增补件数',
    key: 'supplementPieceNum',
    dataIndex: 'supplementPieceNum',
    width: 150,
  },
  {
    title: '整件个数',
    key: 'pieceCount',
    dataIndex: 'pieceCount',
    width: 150,
  },
  {
    title: '增补人',
    key: 'supplementPerson',
    dataIndex: 'supplementPerson',
    width: 150,
  },
  {
    title: '生产单号',
    key: 'weavingCode',
    dataIndex: 'weavingCode',
    width: 150,
  },
  {
    title: '纱牌',
    key: 'brandName',
    dataIndex: 'brandName',
    width: 150,
  },
  {
    title: '单位',
    key: 'unit',
    dataIndex: 'unit',
    width: 150,
  },
  {
    title: '色号',
    key: 'colorCode',
    dataIndex: 'colorCode',
    width: 150,
  },
  {
    title: '色称',
    key: 'colorName',
    dataIndex: 'colorName',
    width: 150,
  },
  {
    title: '备注',
    key: 'remark',
    dataIndex: 'remark',
    width: 150,
  },
  {
    title: '加急件数',
    key: 'urgentCount',
    dataIndex: 'urgentCount',
    width: 150,
  },
  {
    title: '创建人',
    key: 'createName',
    dataIndex: 'createName',
    width: 150,
  },
  {
    title: '创建时间',
    key: 'createTime',
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: '操作',
    key: 'cz',
    dataIndex: 'cz',
    slotName: 'cz',
    width: 150,
    fixed: 'right',
  },
  {
    title: '审核状态',
    key: 'auditState',
    dataIndex: 'auditState',
    slotName: 'auditState',
    width: 150,
    fixed: 'right',
  },
]
let zbdshss: any[] = zbdList.map((o: any) => {
  let obj = {
    headerName: o.title,
    field: o.key,
    pinned: o['fixed'],
  }
  if (o.slotName === 'cz') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['lockPosition'] = 'left'
    ;(obj['width'] = 120),
      (obj['cellRenderer'] = {
        template: `
            <el-button v-if="b==0" style="color:#165dff;" @click="a" class="gesture" link>修改</el-button>
            <el-button v-else style="color:#ccc;" class="gesture" link>修改</el-button>
          `,
        setup(props: any) {
          const a = () => {
            editHandler2(props.params.data)
          }
          return {
            a,
            b: props.params.data.disposeState,
          }
        },
      })
  }
  if (o.key === 'auditState') {
    obj['resizable'] = false
    obj['sortable'] = false
    // obj["lockPosition"] = "right"
    obj['width'] = 120
    obj['cellRenderer'] = {
      template: `
        <el-tag v-if="b == 1" type="success">已审核</el-tag>
        <el-tag v-if="b == 0" type="warning">未审核</el-tag>
      `,
      setup(props: any) {
        return {
          b: props.params.data.disposeState,
        }
      },
    }
    obj['filterParams'] = {
      valueFormatter: function (params: any) {
        return params.value == '0' ? '未审核' : params.value == '1' ? '已审核' : ''
      },
    }
  }

  return obj
})
zbdshss = a.concat(zbdshss)
const zbdDatas = ref([])
const gridOption2 = ref()
const colState2 = ref()
const gridReady2 = (params: any) => {
  gridOption2.value = params.api
  colState2.value = params.columnApi
  //gridOption.value.sizeColumnsToFit();
}
const total2 = ref(0)
const page2 = ref(1)
const size2 = ref(10)

function PageSize2(val: any) {
  page2.value = val
  doRefresh2()
}

function change12(val: any) {
  size2.value = val
  doRefresh2()
}

async function doRefresh2() {
  if (pageData2.dropDownDataqszs != undefined) {
    var startDate = pageData2.dropDownDataqszs.startDate
    var endDate = pageData2.dropDownDataqszs.endDate
    let data1 = startDate
    let data2 = endDate
    var formatDate1 = new Date(startDate)
    var formatDate2 = new Date(endDate)
    if (formatDate1 > formatDate2) {
      startDate = data2 ? data2 + ' 00:00:00' : ''
      endDate = data1 ? data1 + ' 23:59:59' : ''
    } else {
      startDate = data1 ? data1 + ' 00:00:00' : ''
      endDate = data2 ? data2 + ' 23:59:59' : ''
    }
  } else {
    ;(startDate = ''), (endDate = '')
  }
  const res = await post({
    url: 'planSingle/planSupplement/getPage',
    data: {
      page: page2.value,
      size: size2.value,
      deleteState: 0,
      auditState: 0,
      startDate,
      endDate,
      planOrderCode: pageData2.zhibudanhao,
      rawmaterialCode: pageData2.yuanliaobianhao,
      rawmaterialName: pageData2.yuanliaomingc,
      disposeState: pageData2.statesState == 2 ? undefined : pageData2.statesState,
    },
  })
  if (res.code == 200) {
    zbdDatas.value = res.data.list
    gridOption2.value.setRowData(res.data.list)
    aggridFs1.resetAgFs()
    total2.value = res.data.total
  }
}

const onSelect = (dateString: any) => {
  if (changesTab.value == 2) {
    pageData2.dropDownDataqszs = {
      startDate: dateString[0],
      endDate: dateString[1],
    }
  } else {
    pageData2.dropDownDataqszs2 = {
      startDate: dateString[0],
      endDate: dateString[1],
    }
  }
}
const onClear = () => {
  pageData3.dropDownDataqszs2 = {}
}
const onSelect2 = (dateString: any) => {
  pageData3.dropDownDataqszs2 = {
    startDate: dateString[0],
    endDate: dateString[1],
  }
}
const onClear2 = () => {
  if (changesTab.value == 2) {
    pageData2.dropDownDataqszs = {}
  } else {
    pageData2.dropDownDataqszs2 = {}
  }
  DateListSelect.value = ['', '']
}
const pageData2: any = reactive({
  dropDownDataqszs: {
    startDate: '',
    endDate: '',
    isShow: true,
    title: '',
  },
  statesState: 0,
  showAdd1: false,
})
const addWeightDialog2 = ref(false)
const addWeightDialog3 = ref(false)
const zbjsNumber = ref()
const zbdObjsUpdata = ref()
const editHandler2 = (datas: any) => {
  zbdObjsUpdata.value = datas
  zbjsNumber.value = datas.supplementPieceNum
  addWeightDialog2.value = true
}
const zbdUpdata = () => {
  if (zbjsNumber.value == 0) {
    Message.error('增补件数不可为0')
    return
  }
  zbdObjsUpdata.value.supplementPieceNum = zbjsNumber.value
  zbdObjsUpdata.value.id = zbdObjsUpdata.value.detailId
  post({
    url: 'planSingle/planSupplementDetail/update',
    data: zbdObjsUpdata.value,
  }).then((res: any) => {
    if (res.code === 200) {
      addWeightDialog2.value = false

      Message.success({
        content: '修改成功',
        duration: 5000,
      })
      doRefresh2()
    } else {
      Message.error({
        content: res.message,
        duration: 5000,
      })
    }
  })
}
const audits = () => {
  if (gridOption2.value.getSelectedRows().length == 0) {
    Message.error('请勾选数据')
    return false
  }
  if (gridOption2.value.getSelectedRows().some((item: any) => item.disposeState === 1)) {
    Message.error('已审核的数据不能重复审核')
    return
  }
  Modal.confirm({
    title: '系统提示',
    content: '是否审核此订单',
    onOk() {
      post({
        url: 'planSingle/planSupplement/audit',
        data: gridOption2.value.getSelectedRows().map((res: any) => {
          return {
            id: res.detailId,
            disposeState: 1,
          }
        }),
      }).then((res: any) => {
        if (res.code === 200) {
          doRefresh2()
          Message.success('审核通过')
        } else {
          Message.error(res.message)
        }
      })
    },
  })
}
const jjStateChanges = (e: any) => {
  if (e.urgentState == 1) {
    nextTick(() => {
      e.urgentCount = e.needPieceNum
    })
  }
}
const pageData3: any = reactive({
  showAdd1: false,
  sideTitle: '修改',
  sideTitle3: '开需求单',
})
const tcA4DataList: any = ref([])
const tc3DataList: any = ref([])
const tcA2DataList: any = ref([])
const tcA1DataList: any = ref([])
const gridOption3 = ref()
const colState3 = ref()
const gridReady3 = (params: any) => {
  gridOption3.value = params.api
  colState3.value = params.columnApi
  //gridOption.value.sizeColumnsToFit();
}

const pagesss: any = reactive({
  page: 1,
  size: 10,
  total: 0,
})

function PageSizes(val: any) {
  pagesss.page = val
  doRefreshs()
}

function change1s(val: any) {
  pagesss.size = val
  doRefreshs()
}

async function doRefreshs() {
  const res = await post({
    url: 'planSingle/planNeed/getPage',
    data: {
      page: pagesss.page,
      size: pagesss.size,
      deleteState: 0,
      auditState: 0,
      needWeight: 1,
      startDate: DateListSelect.value[0],
      endDate: DateListSelect.value[1],
      planOrderCode: pageData3.zhibudanhao,
      rawmaterialCode: pageData3.yuanliaobianhao,
      rawmaterialName: pageData3.yuanliaomingc,
      firmId: pageData3.corporateId,
      areaName: pageData3.areaName,
      disposeState: pageData3.statesState == 3 ? undefined : pageData3.statesState,
    },
  })
  if (res.code == 200) {
    tc3DataList.value = res.data.list
    pagesss.total = res.data.total
    setTableTotalRow(gridOption3, tc3DataList.value, ['needWeight', 'needPieceNum', 'urgentCount'])
  }
}
const areaNameList = ref([])
const getAreaNameList = async () => {
  try {
    const res = await post({
      url: 'planSingle/planSchedul/getMachineAreaPara',
      data: {
        firmId: pageData3.corporateId,
      },
    })
    if (res.code == 200) {
      console.log('getMachineAreaPara', res)
      areaNameList.value = res.data
    } else {
      Message.error(res.message)
    }
  } catch (e) {
    console.log(e)
  }
}

const selectCx = () => {
  pagesss.page = 1
  doRefreshs()
}

let tc3: any[] = tableColumns3.map((o: any) => {
  let obj = {
    headerName: o.title,
    field: o.key,
    pinned: o['fixed'],
  }
  if (o.slotName === 'disposeState') {
    obj['resizable'] = false
    obj['sortable'] = false
    // obj['lockPosition'] = 'left'
    ;(obj['width'] = 120),
      (obj['cellRenderer'] = {
        template: `
            <a-space>
              <el-tag type="success" v-if="submitState == 0">未处理</el-tag>
              <el-tag type="warning" v-if="submitState == 1">已处理</el-tag>
              <el-tag type="warning" v-if="submitState == 2">已作废</el-tag>
            </a-space>
          `,
        setup(props: any) {
          return {
            submitState: props.params.data.disposeState,
          }
        },
      })
    obj['filterParams'] = {
      valueFormatter: function (params: any) {
        return params.value == '0'
          ? '未处理'
          : params.value == '1'
          ? '已处理'
          : params.value == '2'
          ? '已作废'
          : ''
      },
    }
  }
  if (o.slotName === 'cz') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['lockPosition'] = 'left'
    ;(obj['width'] = 120),
      (obj['cellRenderer'] = {
        template: `
            <a-space>
              <el-button style="color:#165dff;" @click="a" class="gesture" link v-if="submitState == 0">修改</el-button>
              <el-button type='info' @click="a" class="gesture" link v-if="submitState == 1" disabled>修改</el-button>
            </a-space>
          `,
        setup(props: any) {
          const a = () => {
            editHandlersss(props.params.data)
          }
          return {
            a,
            submitState: props.params.data.disposeState,
          }
        },
      })
  }

  return obj
})

tc3 = a.concat(tc3)

const visible: any = ref()

const searchData: any = reactive({
  warehouseId: null,
  firmId: null,
})
const whService = new WHService()
const fhWhList: any = whService.whList
const changeCascader = (data: any) => {
  const { corporateId, sectorId, sectorLabel, corporateLabel } = data
  searchData.warehouseId = ''
  searchData.firmId = corporateId
  whService.getWarhouseListByFirmId(corporateId, '原纱仓')
}
const configCascader = ref<{}>({
  corporateWidth: '15rem', //公司宽度
  sectorWidth: '180px', //部门宽度
  corporateRquired: true, //公司是否必填
  sectorRquired: false, //部门是否必填
  size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
  corporateName: '发货公司', //公司label
  sectorName: '选择部门', //部门label
  cascaderShow: 'sector', //配置部门不显示
})
const chuangjianlinliaodans = () => {
  fhWhList.value = []
  searchData.warehouseId = null
  searchData.firmId = null
  visible.value = true
}

const formRef2: any = ref()
const corPor: any = ref()

const handleOk = async () => {
  const err = await formRef2.value.validate()
  if (!err) {
    const res: any = await post({
      url: 'planSingle/planMaterial/saveTotalOrder',
      data: {
        warehouseId: searchData.warehouseId,
      },
    })
    if (res.code === 200) {
      doRefreshs()
      corPor.value.resetForm()
      Message.success('汇总成功')
      return true
    } else {
      Message.error(res.message)
      return false
    }
  }
}
const handleCancel = () => {
  corPor.value.resetForm()
  visible.value = false
}
const objectOP = reactive<{
  needWeight: any
  needPieceNum: any
  pieceWeight: any
  urgentCount: any
}>({
  needWeight: null,
  needPieceNum: null,
  pieceWeight: null,
  urgentCount: null,
})
const objectOB: any = reactive({
  urgentJTH: '',
  urgentZBDH: '',
  nameList2: [],
  // urgentJTH2: '',
})

const sideOk333 = () => {
  post({
    url: '/planSingle/planNeedDetail/update',
    data: [objectOP],
  }).then((res: any) => {
    if (res.code === 200) {
      pageData3.showAdd1 = false
      Message.success({
        content: '修改成功',
        duration: 5000,
      })
      doRefreshs()
    } else {
      Message.error({
        content: res.message,
        duration: 5000,
      })
    }
  })
}
const editHandlersss = (record: any) => {
  for (var key in record) {
    objectOP[key] = record[key]
  }
  pageData3.sideTitle = '修改需求单'
  if (record.disposeState == 0) {
    pageData3.showAdd1 = true
  } else {
    pageData3.showAdd1 = false
  }
}

const zdList: any = ref([])

const zdClicks = () => {
  post({
    url: 'dict/dictTypeDetail/getListByCodeType?codeType=42',
  }).then((res: any) => {
    if (res.code == 200) {
      zdList.value = res.data
    }
  })
}
const dblclicksShowA1 = ref(false)
const dblclicksShowA2 = ref(false)
const dblclicksShowA3 = ref(false)
const dblclicksShowA4 = ref(false)
const dblclicksShow = ref(false)
const fruitSelects: any = ref('')
const fruitSelectsRemark: any = ref('')
let xzRemarks: any
// const dblclicks = (record: any) => {
//   xzRemarks = record
//   xzRemarks.remark = ''
//   fruitSelects.value = ''
//   zdClicks()
//   dblclicksShow.value = true
// }
const resList = ref()
const dblclicks = (res: any) => {
  xzRemarks = {}
  xzRemarks.remark = ''
  fruitSelects.value = ''
  zdClicks()
  fruitSelectsRemark.value = res.remark
  resList.value = res
  dblclicksShow.value = true
}

const fruitSelectDsty = () => {
  // xzRemarks.remark = xzRemarks.remark + fruitSelects.value.join(',') + ','
  // 去除勾选数据，将新组成的字符串赋值给对应的字段，并重置表格组件
  if (pageData3.sideTitle3 == '开增补单') {
    // gridOptionAz.value.getSelectedRows()[0].remark = fruitSelectsRemark.value
    resList.value.remark = fruitSelectsRemark.value
    tableColumns1List2.value.map((item): any => {
      // 如果当前元素的id与resList.value.id匹配，则返回合并后的对象，否则返回原元素
      return item.id === resList.value.id ? { ...item, ...resList.value } : item
    })
    const listData: any = []
    gridOptionAz.value.forEachNode((node: any) => {
      listData.push(node.data)
    })
    nextTick(() => {
      gridOptionAz.value.setRowData(listData)
    })
    dblclicksShow.value = false
  } else if (pageData3.sideTitle3 == '开需求单') {
    // gridOptionAz1.value.getSelectedRows()[0].remark = fruitSelectsRemark.value
    resList.value.remark = fruitSelectsRemark.value
    tableColumns1List.value.map((item): any => {
      // 如果当前元素的id与resList.value.id匹配，则返回合并后的对象，否则返回原元素
      return item.id === resList.value.id ? { ...item, ...resList.value } : item
    })
    const listData: any = []
    gridOptionAz1.value.forEachNode((node: any) => {
      listData.push(node.data)
    })
    nextTick(() => {
      // gridOptionAz1.value.setRowData(listData)
    })
    dblclicksShow.value = false
  }
}

//当件重改变  重量=件重*整件件重 (重量不可修改)
function changeJs(event: any) {
  if (objectOP.urgentCount && event < objectOP.urgentCount) {
    objectOP.urgentCount = event
  }
  // console.log(objectOP.pieceWeight)
  objectOP.needWeight = (event * objectOP.pieceWeight).toFixed(2)
  objectOP.needWeight = Number(objectOP.needWeight)
}

const cels = () => {
  if (gridOption2.value.getSelectedRows().length == 0) {
    Message.error('请勾选数据')
    return false
  }
  if (gridOption2.value.getSelectedRows().some((item: any) => item.disposeState === 1)) {
    Message.error('已审核的数据不能作废')
    return
  }

  Modal.confirm({
    title: '系统提示',
    content: '是否作废此订单',
    onOk() {
      post({
        url: 'planSingle/planSupplement/audit',
        data: gridOption2.value.getSelectedRows().map((res: any) => {
          return {
            id: res.mainId,
            auditState: 2,
          }
        }),
      }).then((res: any) => {
        if (res.code === 200) {
          doRefresh2()
          Message.success('订单已作废')
        } else {
          Message.error(res.message)
        }
      })
    },
  })
}

const celss = () => {
  if (gridOption3.value.getSelectedRows().length == 0) {
    Message.error('请勾选数据')
    return false
  }
  if (gridOption3.value.getSelectedRows().some((item: any) => item.disposeState === 1)) {
    Message.error('已审核的数据不能作废')
    return
  }
  if (gridOption3.value.getSelectedRows().some((item: any) => item.disposeState === 2)) {
    Message.error('已作废的数据不能作废')
    return
  }

  Modal.confirm({
    title: '系统提示',
    content: '是否作废此订单',
    onOk() {
      post({
        url: 'planSingle/planNeed/setCancel',
        data: gridOption3.value.getSelectedRows().map((res: any) => {
          return {
            id: res.id,
            disposeState: 2,
          }
        }),
      }).then((res: any) => {
        if (res.code === 200) {
          doRefreshs()
          Message.success('订单已作废')
        } else {
          Message.error(res.message)
        }
      })
    },
  })
}
const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
  saveOrUpdateGridState01('setingSelects-1', gridOption, colState, tableColumns)
const onColumnMoved = () => {
  saveGridState01()
}
const onColumnResized = () => {
  saveGridState01()
}
const onColumnVisible = () => {
  saveGridState01()
}
const { saveGridState: saveGridState02, updateGridState: updateGridState02 } =
  saveOrUpdateGridState02('setingSelects-2', gridOption2, colState2, zbdshss)
const onColumnMoved2 = () => {
  saveGridState02()
}
const onColumnResized2 = () => {
  saveGridState02()
}
const onColumnVisible2 = () => {
  saveGridState02()
}
const { saveGridState: saveGridState03, updateGridState: updateGridState03 } =
  saveOrUpdateGridState03('setingSelects-3', gridOption3, colState3, tc3)
const onColumnMoved3 = () => {
  saveGridState03()
}
const onColumnResized3 = () => {
  saveGridState03()
}
const onColumnVisible3 = () => {
  saveGridState03()
}
const DateListSelect: any = ref([])

const paper = async () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return
  }
  post({
    url: 'planSingle/planSchedul/printShippingData',
    data: gridOption.value.getSelectedRows(),
    responseType: 'blob',
  }).then((zzx: any) => {
    let reader = new FileReader()
    reader.readAsDataURL(zzx)
    reader.onload = function () {
      let pdfBase64 = reader.result.replace('data:application/pdf;base64,', '')
      printJS({ printable: pdfBase64, type: 'pdf', base64: true })
    }
  })
}
const bfShowAdd: any = ref(false)
let srcUrl = ref()
const dyBoufeixs = async () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return
  }
  if (gridOption.value.getSelectedRows().length > 1) {
    Message.error('只能勾选一条')
    return
  }
  // const jvData: any = table.dataList.filter((res: any) => {
  //   return gridOption.value.getSelectedRows()[0] == res.id
  // })
  // if (jvData[0].customName == '') {
  if (gridOption.value.getSelectedRows()[0].customName == '') {
    Message.error('该计划单没有选择客户名称')
    return
  } else {
    const res: any = await post({
      url: 'planSingle/clothfiy/getAutomaticInfo',
      data: {
        // customName: jvData[0].customName
        customName: gridOption.value.getSelectedRows()[0].customName,
      },
    })
    if (res.code == 200) {
      // srcUrl.value = `./hiprint/custom2.html?modelData=${JSON.stringify(res.data)}&jhd=${jvData[0].planOrderCode}`
      srcUrl.value = `./hiprint/custom2.html?modelData=${JSON.stringify(res.data)}&jhd=${
        gridOption.value.getSelectedRows()[0].planOrderCode
      }`
      bfShowAdd.value = true
    } else {
      Message.error(res.message)
    }
  }
}
const bc = () => {
  pageData.showAdd2 = false
  bfShowAdd.value = false
}
const zjwj = () => {
  post({
    url: 'planSingle/planMachineTask/pmtFinish',
    data: [wjListObj.value],
  }).then(({ code, message }) => {
    if (code == 200) {
      Message.success('完结成功')
      addWeightDialog3.value = false
      doRefresh()
    } else {
      Message.error(message)
    }
  })
}
const pjwj = () => {
  post({
    url: 'planSingle/planMachineTask/pmtAverageFinish',
    data: wjListObj.value,
  }).then(({ code, message }) => {
    if (code == 200) {
      Message.success('完结成功')
      addWeightDialog3.value = false
      doRefresh()
    } else {
      Message.error(message)
    }
  })
}
let tcA2: any[] = [
  {
    showRowGroup: 'hide_def',
    headerName: '',
    checkboxSelection: true,
    headerCheckboxSelection: true,
    pinned: 'left',
    width: 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: 'left',
  },
  {
    headerName: '机台编号',
    field: 'machineCode',
    pinned: 'fixed',
  },
  {
    headerName: '类型',
    field: 'machineTypeName',
    pinned: 'fixed',
  },
  {
    headerName: '位置',
    field: 'floorDistrict',
    pinned: 'fixed',
  },
  {
    headerName: '机器名称',
    field: 'machineName',
    pinned: 'fixed',
  },
  {
    headerName: '区域',
    field: 'areaName',
    pinned: 'fixed',
  },
]
let tcA4: any[] = [
  {
    showRowGroup: 'hide_def',
    headerName: '',
    checkboxSelection: true,
    headerCheckboxSelection: true,
    pinned: 'left',
    width: 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: 'left',
  },
  {
    headerName: '生产序号',
    field: 'serialNum',
    width: 150,
  },
  {
    headerName: '生产单号',
    field: 'weavingCode',
    width: 150,
  },
  {
    headerName: '机台号',
    field: 'machineCode',
    width: 200,
  },
  {
    headerName: '预计上线时间',
    field: 'startTime',
    width: 150,
  },
  {
    headerName: '预计完成时间',
    field: 'endTime',
    width: 150,
  },
  {
    headerName: '分配重量',
    field: 'alreadyWeight',
    width: 150,
  },
  {
    headerName: '织布单号',
    field: 'planOrderCode',
    width: 150,
  },
  {
    headerName: '生产状态',
    field: 'productionState',
    slotName: 'productionState',
    width: 120,
    fixed: 'right',
    cellRenderer: {
      template: `<span>{{ a1 }}</span>`,
      setup(props: any) {
        return {
          a1:
            props.params.data.productionState == 0
              ? '等待'
              : props.params.data.productionState == 1
              ? '生产中'
              : props.params.data.productionState == 2
              ? '完成'
              : '暂停',
        }
      },
    },
    filterParams: {
      valueFormatter: function (params: any) {
        return params.value == '0'
          ? '等待'
          : params.value == '1'
          ? '生产中'
          : params.value == '2'
          ? '完成'
          : '暂停'
      },
    },
  },
]
// 新增机台按钮
const zjjts = () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return
  }
  post({
    url: 'planSingle/planSchedul/getMachineByOrder',
    data: gridOption.value.getSelectedRows(),
  }).then(({ code, message, data }) => {
    if (code == 200) {
      tcA1DataList.value = data
      dblclicksShowA1.value = true
    } else {
      Message.error(message)
    }
  })
}
// 暂停按钮事件
const zts = () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return
  }
  visible1.value = true
  console.log(visible1.value, '1')
  // post({
  //   url: 'planSingle/planMachineTask/setSuspend',
  //   data: gridOption.value.getSelectedRows().map((o: any) => { return o.id })
  // }).then(({ code, message, data }) => {
  //   if (code == 200) {
  //     doRefresh()
  //   } else {
  //     Message.error(message)
  //   }
  // })
}
const tjdd = () => {
  post({
    url: 'planSingle/planMachineTask/setSuspend',
    data: {
      id: gridOption.value.getSelectedRows()[0].id,
      adjustmentState: gridOption.value.getSelectedRows()[0].adjustmentState,
      stopType: '停机等待',
    },
  }).then(({ code, message }) => {
    if (code == 200) {
      doRefresh()
      visible1.value = false
      // agClousData2.value = []
      Message.success(message)
    } else {
      Message.error(message)
    }
  })
}

const ztzzxyd = () => {
  post({
    url: 'planSingle/planMachineTask/setSuspend',
    data: {
      id: gridOption.value.getSelectedRows()[0].id,
      adjustmentState: gridOption.value.getSelectedRows()[0].adjustmentState,
      stopType: '暂停转做下单',
    },
  }).then(({ code, message }) => {
    if (code == 200) {
      doRefresh()
      visible1.value = false
      // agClousData2.value = []
      Message.success(message)
    } else {
      Message.error(message)
    }
  })
}
const visible1 = ref(false)
// 取消暂停按钮事件
const qxzts = () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return
  }
  // dblclicksShowA3.value = true
  Modal.confirm({
    title: '系统提示',
    content: '确认取消暂停选中的数据?',
    onOk: () => {
      post({
        url: 'planSingle/planMachineTask/updateDate',
        data: {
          id: gridOption.value.getSelectedRows()[0].id,
          productionState: 0,
          suspendState: 0,
          suspendTime: '',
          suspendName: '',
          stopType: '',
        },
      }).then((res: any) => {
        if (res.code == 200) {
          doRefresh()
          // agClousData2.value = []
          Message.success(res.message)
        } else Message.error(res.message)
      })
    },
  })
}
// 取消暂停弹窗转机台按钮
const saveZjtOP = () => {
  post({
    url: 'planSingle/planSchedul/getMachineByOrder',
    data: gridOption.value.getSelectedRows(),
  }).then(({ code, message, data }) => {
    if (code == 200) {
      tcA2DataList.value = data
      dblclicksShowA2.value = true
      dblclicksShowA3.value = false
    } else {
      Message.error(message)
    }
  })
}
// 取消暂停弹窗确定按钮
const saveZjtOB = () => {
  post({
    url: 'planSingle/planMachineTask/setCancelSuspend',
    data: gridOption.value.getSelectedRows(),
  }).then(({ code, message, data }) => {
    if (code == 200) {
      doRefresh()
      dblclicksShowA3.value = false
    } else {
      Message.error(message)
    }
  })
}
// 新增机台保存按钮
const saveXZjt = () => {
  if (gridOptionA1.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return
  }
  post({
    url: 'planSingle/planSchedul/getMathInfo',
    data: gridOptionA1.value.getSelectedRows(),
  }).then(({ code, message, data }) => {
    if (code == 200) {
      let ob = data
      post({
        url: 'planSingle/planSchedul/saveMachineByOrder',
        data: ob,
      }).then(({ code, message, data }) => {
        if (code == 200) {
          dblclicksShowA1.value = false
          doRefresh()
        } else {
          Message.error(message)
        }
      })
    } else {
      Message.error(message)
    }
  })
}
// 转机台按钮
const zjts = () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return
  }
  post({
    url: 'planSingle/planSchedul/getMachineByOrder',
    data: gridOption.value.getSelectedRows(),
  }).then(({ code, message, data }) => {
    if (code == 200) {
      tcA2DataList.value = data
      dblclicksShowA2.value = true
    } else {
      Message.error(message)
    }
  })
}
// 转机台确认按钮
const saveZjt = () => {
  if (gridOptionA2.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return
  }
  post({
    url: 'planSingle/planSchedul/saveChangeMachineByOrder',
    data: {
      old: gridOption.value.getSelectedRows(),
      newMachineCode: gridOptionA2.value.getSelectedRows()[0].machineCode,
    },
  }).then(({ code, message, data }) => {
    if (code == 200) {
      doRefresh()
      dblclicksShowA2.value = false
    } else {
      Message.error(message)
    }
  })
}
// 转做下单操作按钮
const editHandler1 = (val: any) => {
  post({
    url: 'planSingle/planSchedul/makeNext',
    data: val,
  }).then(({ code, message, data }) => {
    if (code == 200) {
      Message.success('操作成功！')
      doRefresh()
    } else {
      Message.error(message)
    }
  })
}
// 插单操作按钮
const editHandler3 = (val: any) => {
  post({
    url: 'planSingle/planMachineTask/getList',
    data: { machineCode: val.machineCode, neId: val.id },
  }).then(({ code, message, data }) => {
    if (code == 200) {
      tcA4DataList.value = data
      dblclicksShowA4.value = true
    } else {
      Message.error(message)
    }
  })
}
// 插单确认按钮
const saveCD = () => {
  if (gridOptionA4.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return
  }
  post({
    url: 'planSingle/planMachineTask/into',
    data: {
      id: gridOption.value.getSelectedRows()[0].id,
      new: gridOptionA4.value.getSelectedRows().map((o: any) => {
        return o.id
      }),
      machineCode: gridOption.value.getSelectedRows()[0].machineCode,
      planOrderCode: gridOption.value.getSelectedRows()[0].planOrderCode,
      state: pageData.radioA,
    },
  }).then(({ code, message, data }) => {
    if (code == 200) {
      doRefresh()
      dblclicksShowA4.value = false
    } else {
      Message.error(message)
    }
  })
}
// 新增机台弹窗中查询方法
const saveJMCX = () => {
  let ob = tcA1DataList.value.filter((item: any) => {
    if (item.machineCode == objectOB.urgentJTH) {
      return item
    }
  })
  if (objectOB.urgentJTH == '' || objectOB.urgentJTH == null || objectOB.urgentJTH == undefined) {
    zjjts()
  } else {
    tcA1DataList.value = ob
  }
}
// 插单弹窗中查询按钮操作
const saveJMCX2 = () => {
  // let ob = ''
  // if (objectOB.urgentJTH2 == '' || objectOB.urgentJTH2 == null || objectOB.urgentJTH2 == undefined) {
  //   ob = gridOption.value.getSelectedRows()[0].machineCode
  // } else {
  //   ob = objectOB.urgentJTH2
  // }
  post({
    url: 'planSingle/planMachineTask/getList',
    data: {
      machineCode: gridOption.value.getSelectedRows()[0].machineCode,
      neId: gridOption.value.getSelectedRows()[0].id,
      planOrderCode: objectOB.urgentZBDH,
    },
  }).then(({ code, message, data }) => {
    if (code == 200) {
      tcA4DataList.value = data
    } else {
      Message.error(message)
    }
  })
}
// aggridFs.onFilterChanged
const FilterChangeds = (params: any) => {
  aggridFs.onFilterChanged(params)
  let data: any = {
    list: [],
  }
  params.api.forEachNodeAfterFilter((row: any) => {
    data.list.push(row.data)
    data.list.forEach(item=>{
      item.productedWeight=Number((item.actualWeight+item.hasProductWeight).toFixed(2))
    })
  })
  if (changesTab.value == 1) {
    
    gridOption.value.setPinnedBottomRowData([
      {
        ckbox: '总计',
        badWeight: one(data.list.map((res) => (res.badWeight ? Number(res.badWeight) : 0))).toFixed(
          2
        ),
        csNum: one(data.list.map((res) => (res.csNum ? Number(res.csNum) : 0))).toFixed(2),
        sgcNum: one(data.list.map((res) => (res.sgcNum ? Number(res.sgcNum) : 0))).toFixed(2),
       
        alreadyWeight: one(
          data.list.map((res) => (res.alreadyWeight ? Number(res.alreadyWeight) : 0))
        ).toFixed(2),
        actualWeight: one(
          data.list.map((res) => (res.actualWeight ? Number(res.actualWeight) : 0))
        ).toFixed(2),
        posteriorWeight: one(
          data.list.map((res) => (res.posteriorWeight ? Number(res.posteriorWeight) : 0))
        ).toFixed(2),
        productWeight: one(
          data.list.map((res) => (res.productWeight ? Number(res.productWeight) : 0))
        ).toFixed(2),
        hasProductWeight: one(
          data.list.map((res) => (res.hasProductWeight ? Number(res.hasProductWeight) : 0))
        ).toFixed(2),
        productedWeight: one(
          data.list.map((res) => (res.productedWeight ? Number(res.productedWeight) : 0))
        ).toFixed(2),
      },
    ])
  } else if (changesTab.value == 3) {
    setTableTotalRow(gridOption3, data.list, ['needWeight', 'needPieceNum', 'urgentCount'])
  }
}
const convertToString = () => {
  if (!fruitSelectsRemark.value?.includes('加急')) {
    if (fruitSelects.value == '') {
      fruitSelectsRemark.value = ''
    } else {
      fruitSelectsRemark.value = fruitSelects.value.join(',') + ','
    }
  } else {
    let oldString = fruitSelectsRemark.value.match(/加急（(\d+)）/)[0]
    console.log(oldString, fruitSelectsRemark.value)

    if (oldString) {
      console.log('!oldString', fruitSelectsRemark.value, fruitSelects.value, oldString)
      if (fruitSelects.value == '') {
        fruitSelectsRemark.value = '' + oldString
      } else {
        console.log('else', fruitSelectsRemark.value, fruitSelects.value, oldString)

        fruitSelectsRemark.value = fruitSelects.value.join(',') + ',' + oldString
      }
    }
  }

  // fruitSelects.value = ''
}

const totalssss = ref(0)
const lenghensssss = (val) => {
  totalssss.value = val
}
</script>
<style lang="less" scoped>
// :deep(.ag-menu) {
//   height: 150px;
// }

// :deep(.arco-scrollbar-track-direction-vertical) {
//   display: none !important;
// }

:deep(.arco-form-item-label) {
  font-size: calc(12px / var(--auto-fixMultiple)) !important;
}

:deep(.arco-checkbox) {
  font-size: calc(14px / var(--auto-fixMultiple)) !important;
}

:deep(.el-button) {
  font-size: calc(14px / var(--auto-fixMultiple)) !important;
}

:deep(.arco-btn) {
  font-size: calc(14px / var(--auto-fixMultiple)) !important;
}

:deep(.ag-header-cell-text) {
  font-size: calc(14px / var(--auto-fixMultiple)) !important;
}

:deep(.ag-cell) {
  font-size: calc(14px / var(--auto-fixMultiple)) !important;
}

:deep(.arco-table-th),
:deep(.arco-table-td) {
  font-size: calc(12px / var(--auto-fixMultiple)) !important;
}

// :deep(.arco-input),
// :deep(.arco-select-view-input) {
//   font-size: calc(14px / var(--auto-fixMultiple)) !important;
// }

// .ag-virtual-list-viewport {
//   overflow: none
// }
</style>
